libname zh '~/taiwan/fies/sasdata'; options ls=72; %macro one(q); /* The data from Taiwan is in card-image format: each observation has variable values spread over up to 99 lines, with a variable # of lines per observation, depending on the amount of available info for that household. Hence the complexity of the following extract */ DATA head (KEEP=hhid areacode urban serial agrtype agr_area agr_work weight ) people (KEEP=hhid person relate sex age educ grad empact empind empocc part empsoc empsta empsit earner marry outpat discrg insnhi ins1si ins1ms ins2si ins2ms ii ) consume (KEEP=hhid colortv ldcdplay video stereo piano videogam vcr cable computer tele answer fax modem auto motorcyc oven acheat dehumid washer drier dishwash kitchfan vaccum geyser fountain microwav newspap periodic ) house (KEEP=hhid ownhome rental allocate otherown res_use bus_use otheruse story_1 story_23 story_45 story_6 wateruse nowater loan noloan ownpark rentpark nopark landarea bldarea leasres leasbus leasboth noleas ) marker (KEEP=hhid daiha value jj ); LENGTH DEFAULT=6; * a length of 6 was chosen because the largest potential integer is 11 characters long; filename myfile "~/taiwan/fies/rawdata/tpis&q..dat"; INFILE myfile; INPUT line 79-80 @; * line number is unique identifier for each line; RETAIN ii jj 0; IF line=1 THEN DO; ii=0; * Counter for the person data set; jj=0; * Counter for the inc, cons, & capital data sets; INPUT hhid $ 1-8 areacode 1-2 urban 3 serial $ 4-8 agrtype 9 agr_area 10 agr_work 11 weight 74-78; OUTPUT head; RETURN; END; ELSE IF 2<=line<=20 THEN DO; INPUT hhid $ 1-8 person 9-10 relate 11-12 sex 13 age 14-15 educ 17-18 grad 19 empact 20 empind 21-22 empocc 23-24 part 25 empsoc 26-27 empsta 28 empsit 29 earner 30 marry 33-34 outpat 35-36 discrg 37-38 insnhi 39-40 ins1si 54-55 ins1ms 56-57 ins2si 58-59 ins2ms 60-61 ; ii=ii+1; * start iterating at ii=1,2,3,... ; OUTPUT people; RETURN; END; ELSE IF line=21 THEN DO; INPUT hhid $ 1-8 colortv 9-10 ldcdplay 11-12 video 13-14 stereo 15-16 piano 17-18 videogam 19-20 vcr 21-22 cable 23-24 computer 25-26 tele 27-28 answer 29-30 fax 31-32 modem 33-34 auto 35-36 motorcyc 37-38 oven 39-40 acheat 41-42 dehumid 43-44 washer 45-46 drier 47-48 dishwash 49-50 kitchfan 51-52 vaccum 53-54 geyser 55-56 fountain 57-58 microwav 59-60 newspap 61-62 periodic 63-64; OUTPUT consume; RETURN; END; ELSE IF line=22 THEN DO; INPUT hhid $ 1-8 ownhome 9 rental 10 allocate 11 otherown 12 res_use 13 bus_use 14 otheruse 15 story_1 19 story_23 20 story_45 21 story_6 22 wateruse 23 nowater 24 loan 29 noloan 30 ownpark 31 rentpark 32 nopark 33 landarea 36-38 bldarea 39-41 leasres 56 leasbus 57 leasboth 58 noleas 59; OUTPUT house; RETURN; END; ELSE IF 23<=line<=99 THEN DO; INPUT hhid $ 1-8 daiha 9-11 @12 value zd11. @; jj=jj+1; * start iterating at jj=1,6,11,16,... ; OUTPUT marker; INPUT hhid $ 1-8 daiha 23-25 @26 value zd11. @; jj=jj+1; * start iterating at jj=2,7,12,17,... ; OUTPUT marker; INPUT hhid $ 1-8 daiha 37-39 @40 value zd11. @; jj=jj+1; * start iterating at jj=3,8,13,18,... ; OUTPUT marker; INPUT hhid $ 1-8 daiha 51-53 @54 value zd11. @; jj=jj+1; * start iterating at jj=4,9,14,19,... ; OUTPUT marker; INPUT hhid $ 1-8 daiha 65-67 @68 value zd11. ; jj=jj+1; * start iterating at jj=5,10,15,20,...; OUTPUT marker; RETURN; END; PROC SORT DATA=head; BY hhid; PROC SORT DATA=people; BY hhid ii; PROC SORT DATA=consume; BY hhid; PROC SORT DATA=house; BY hhid; PROC SORT DATA=marker; BY hhid jj; PROC TRANSPOSE DATA=people OUT=people2 PREFIX=new1; BY hhid ii; PROC TRANSPOSE DATA=marker OUT=marker2 PREFIX=new2; BY hhid jj; DATA people2; LENGTH DEFAULT=6; SET people2; var1=TRIM(_name_)||TRIM(ii); var1=COMPRESS(var1); DROP _name_ ii; DATA marker2; LENGTH DEFAULT=6; SET marker2; var2=TRIM(_name_)||TRIM(jj); var2=COMPRESS(var2); DROP _name_ jj; PROC TRANSPOSE DATA=people2 OUT=people2; BY hhid; ID var1; PROC TRANSPOSE DATA=marker2 OUT=marker2; BY hhid; ID var2; DATA zh.data&q; LENGTH DEFAULT=6; MERGE head people2 consume house marker2; BY hhid; PROC CONTENTS; run; %mend; %one(99); %one(00); %one(01);