BookmarkSubscribeRSS Feed
SGic
Calcite | Level 5

Hi, I need help to figure out why do I get this error. This is the part of the code used:

(please note that this is only part of the program I wrote, which worked fine until I added these new lines. The reason for having multiple same variables in the array below is that the data was collected each 4 years and I need to have them for each year period. This approach works well for other variables.)

 

proc rank ties=mean out=NEW;
var mddw91 mddw95 mddw99;
ranks mddw91r mddw95r mddw99r ;
proc sort; by id; run;

 

array mddwr[*]     mddw91r mddw91r mddw91r mddw91r mddw95r mddw95r mddw95r mddw95r mddw99r mddw99r mddw99r;

 

For some reason, this array results in an error, while other arrays already there, that have been created with an identical format, work just fine.

 

Thanks!!

8 REPLIES 8
Reeza
Super User

Post the full log. 

SGic
Calcite | Level 5

It is really long, so I copied a part that i think is relevant. Please let me know if you think I need to send you the full code/log. Thanks v. much!


28359 *Main Dietary Variables;
28360 array dietq[*] diet91 diet91 diet91 diet91 diet95 diet95 diet95 diet95 diet99 diet99 diet99;
28361 array mddw[*] mddw91 mddw91 mddw91 mddw91 mddw95 mddw95 mddw95 mddw95 mddw99 mddw99 mddw99;
28362 array mddwq[*] mddw91q mddw91q mddw91q mddw91q mddw95q mddw95q mddw95q mddw95q mddw99q mddw99q mddw99q;
28363 array mddwr[*] mddw91r mddw91r mddw91r mddw91r mddw95r mddw95r mddw95r mddw95r mddw99r mddw99r mddw99r;
28364 array fgi3wk[*] fgi3wk91 fgi3wk91 fgi3wk91 fgi3wk91 fgi3wk95 fgi3wk95 fgi3wk95 fgi3wk95 fgi3wk99 fgi3wk99
28364 ! fgi3wk99;
28365 array fgi1d[*] fgi1d91 fgi1d91 fgi1d91 fgi1d91 fgi1d95 fgi1d95 fgi1d95 fgi1d95 fgi1d99 fgi1d99 fgi1d99;
28366 array fgi3wkq[*] fgi3wk91q fgi3wk91q fgi3wk91q fgi3wk91q fgi3wk95q fgi3wk95q fgi3wk95q fgi3wk95q fgi3wk99q
28366 ! fgi3wk99q fgi3wk99q;
28367 array fgi1dq[*] fgi1d91q fgi1d91q fgi1d91q fgi1d91q fgi1d95q fgi1d95q fgi1d95q fgi1d95q fgi1d99q fgi1d99q
28367 ! fgi1d99q;
28368 array fgi3wkr[*] fgi3wk91r fgi3wk91r fgi3wk91r fgi3wk91r fgi3wk95r fgi3wk95r fgi3wk95r fgi3wk95r fgi3wk99r fgi3wk99r
28368 ! fgi3wk99r;
28369 array fgi1dr[*] fgi1d91r fgi1d91r fgi1d91r fgi1d91r fgi1d95r fgi1d95r fgi1d95r fgi1d95r fgi1d99r fgi1d99r fgi1d99r;
28370 array ahei10[*] ahei10_91 ahei10_91 ahei10_91 ahei10_91 ahei10_95 ahei10_95 ahei10_95 ahei10_95 ahei10_99 ahei10_99
28370 ! ahei10_99;
28371 array ahei10c[*] ahei10_91c ahei10_91c ahei10_91c ahei10_91c ahei10_95c ahei10_95c ahei10_95c ahei10_95c ahei10_99c
28371 ! ahei10_99c ahei10_99c;
28372 array ahei10q[*] ahei10_91q ahei10_91q ahei10_91q ahei10_91q ahei10_95q ahei10_95q ahei10_95q ahei10_95q ahei10_99q
28372 ! ahei10_99q ahei10_99q;
28373 array ahei10r[*] ahei10_91r ahei10_91r ahei10_91r ahei10_91r ahei10_95r ahei10_95r ahei10_95r ahei10_95r ahei10_99r
28373 ! ahei10_99r ahei10_99r;
28374 array ahei10cq[*] ahei10_91cq ahei10_91cq ahei10_91cq ahei10_91cq ahei10_95cq ahei10_95cq ahei10_95cq ahei10_95cq
28374 ! ahei10_99cq ahei10_99cq ahei10_99cq;
28375 array pdqs[*] test391 test391 test391 test391 test395 test395 test395 test395 test399 test399 test399;
28376 array pdqsq[*] test391q test391q test391q test391q test395q test395q test395q test395q test399q test399q test399q;
28377 array pdqsr[*] test391r test391r test391r test391r test395r test395r test395r test395r test399r test399r test399r;


***Continuous score**;
28455
28456 mddwscore=mddw[i];
28457 fgi3wkscore=fgi3wk[i];
28458 fgi1dscore=fgi1d[i];
28459 ahei10score=ahei10[i];
ERROR: Illegal reference to the array mddwr.
28460 ahei10cscore=ahei10c[i];
ERROR: Illegal reference to the array fgi3wkr.
28461 pdqsscore=pdqs[i];
ERROR: Illegal reference to the array fgi1dr.
28462
ERROR: Illegal reference to the array ahei10r.
28463 ***Probit score******;
ERROR: Illegal reference to the array pdqsr.
28464 mddwpbit=PROBIT(mddwr/15233);
28465 fgi3wkpbit=PROBIT(fgi3wkr/15233);
28466 fgi1dpbit=PROBIT(fgi1dr/15233);
28467 ahei10pbit=PROBIT(ahei10r/15233);
28468 pdqspbit=PROBIT(pdqsr/15233);
28469

 

Reeza
Super User

Include the full error message and how you're looping/setting i in your code. 

 

The error is very helpful in debugging the messages. Not seeing any DO/TO I don't know if the code is incorrect and you don't understand how arrays work or if the code was excluded. 


When pasting long code please use a code box, see the notepad icon or the { i } icon to add a code box.

SGic
Calcite | Level 5
7:WARNING: Unable to copy SASUSER registry to WORK registry. Because of this, you will not see registry customizations during 
566:      One or more lines were truncated.
644:      One or more lines were truncated.
1144:28301      *SKIP Each Questionnaire Period with Missing/Invalid FFQ Data (d91=.);
1355:ERROR: Illegal reference to the array mddwr.
1357:ERROR: Illegal reference to the array fgi3wkr.
1359:ERROR: Illegal reference to the array fgi1dr.
1361:ERROR: Illegal reference to the array ahei10r.
1363:ERROR: Illegal reference to the array pdqsr.
2137:WARNING: The data set WORK.NEW1 may be incomplete.  When this step was stopped there were 0 observations and 2002 variables.
2690:ERROR: Errors printed on page 18.
*MERGE FILES;
	data NEW (sortedby=id);
	merge 	
	der8911(in=main) 
	nur89(in=q89) nur91(in=q91) nur93(in=q93) nur95(in=q95) nur97(in=q97) nur99(in=q99) nur01(in=q01) 
	n91_nts(in=d91) n95_nts(in=d95) n99_nts(in=d99)
	n91_dt n95_dt n99_dt
	death dmfile canfile pa mddw fgi ahei pdqs
	end=_end_; by id; 
	exrec=1; if first.id and main then exrec=0;

	if q93 then qm93=1; else qm93=0;
	if q95 then qm95=1; else qm95=0;
	if q97 then qm97=1; else qm97=0;
	if q99 then qm99=1; else qm99=0;
	if q01 then qm01=1; else qm01=0;

	if d91 then diet91=1; else diet91=0; 
	if d95 then diet95=1; else diet95=0;
	if d99 then diet99=1; else diet99=0;


/*====================================Data cleaning=====================================*/
	
*Adjusting Retmo Ranges;

   
        if retmo91<1098 then retmo91=1098; else if retmo91>=1122 then retmo91=1122;
        if retmo93<1122 then retmo93=1122; else if retmo93>=1146 then retmo93=1146;
        if retmo95<1146 then retmo95=1146; else if retmo95>=1170 then retmo95=1170;
        if retmo97<1170 then retmo97=1170; else if retmo97>=1194 then retmo97=1194;
        if retmo99<1194 then retmo99=1194; else if retmo99>=1218 then retmo99=1218;
        if retmo01<1218 then retmo01=1218; else if retmo01>=1242 then retmo01=1242;
        cutoff=1242;
       
   
        retmo92=1110;
        retmo94=1134;
        retmo96=1158;
        retmo98=1182;
        retmo00=1206;
        retmo02=1230;

       
*Carry Forward Missing Diet Exposure Data;
	array data91[*] diet91 mddw91 fgi3wk91 fgi1d91 ahei10_91 ahei10_91c test391 alco91n calor91n;
		
	array data95[*] diet95 mddw95 fgi3wk95 fgi1d95 ahei10_95 ahei10_95c test395 alco95n calor95n;
		
	array data99[*] diet99 mddw99 fgi3wk99 fgi1d99 ahei10_99 ahei10_99c test399 alco99n calor99n;


	do i=1 to 9;
		if data95[i]=. then data95[i]=data91[i];
		if data99[i]=. then data99[i]=data95[i]; 

*Cumulative Average Update;				/*PPP: corrected cumulative average programming*/
	data95[i]=mean(data95[i],data91[i]);
	data99[i]=mean(data99[i],data95[i],data91[i]);

	end; 
	run;

*Create Quintiles for Variables;
	proc rank groups=5 out=NEW; 
	var 	mddw91 mddw95 mddw99  
	 		fgi3wk91 fgi3wk95 fgi3wk99 
			fgi1d91 fgi1d95 fgi1d99
 			ahei10_91c ahei10_91 ahei10_95c ahei10_95 ahei10_99c ahei10_99
  			test391 test395 test399; 
			
  			
	ranks	mddw91q mddw95q mddw99q 
	 		fgi3wk91q fgi3wk95q fgi3wk99q 
			fgi1d91q fgi1d95q fgi1d99q
 			ahei10_91cq ahei10_91q ahei10_95cq ahei10_95q ahei10_99cq ahei10_99q
  			test391q test395q test399q;
  					
	proc sort; by id; run;

	proc rank groups=5 out=NEW;
			var	calor91n calor95n calor99n cof91d coff95d coff99d;
	
	ranks	cal91q cal95q cal99q cof91q cof95q cof99q;
	
	proc sort; by id; run;

	
 *Percentiles for standardization of continuous scores;
        proc rank groups=100 out=NEW;
        var     mddw91 mddw95 mddw99  
	 			fgi3wk91 fgi3wk95 fgi3wk99 
				fgi1d91 fgi1d95 fgi1d99
 				ahei10_91 ahei10_95 ahei10_99
  				test391 test395 test399;
        ranks   mddw91p mddw95p mddw99p  
	 			fgi3wk91p fgi3wk95p fgi3wk99p 
				fgi1d91p fgi1d95p fgi1d99p
 				ahei10_91p ahei10_95p ahei10_99p
  				test391p test395p test399p;
                proc sort; by id; run;	
	
proc rank ties=mean out=NEW;
 var     		mddw91 mddw95 mddw99  
	 			fgi3wk91 fgi3wk95 fgi3wk99 
				fgi1d91 fgi1d95 fgi1d99
 				ahei10_91 ahei10_95 ahei10_99
  				test391 test395 test399;
  		ranks   mddw91r mddw95r mddw99r  
	 			fgi3wk91r fgi3wk95r fgi3wk99r 
				fgi1d91r fgi1d95r fgi1d99r
 				ahei10_91r ahei10_95r ahei10_99r
  				test391r test395r test399r;
                proc sort; by id; run;

				
		
/*====================CREATING PERSON-TIME RISK SET INTERVALS===========================*/

data NEW1; set NEW end=_end_;

/*PPP NOTE: This macro isn't being used for the traditional survival analysis. It is being used to create 1 row for each year a pregnancy is reported,
	which we have information for on an ANNUAL basis (rather than biennially). Thus, the array is on an annual basis, beginning in 1992. 
	Pregnancies are only included if reported AFTER the return of 1991 FFQ (thus on the 1993 questionnaire or later), to capture PRE-pregnancy 
	diet only. Thus, pregnancies reported ON the 1991 questionnaire are not included in this analysis.  
	*/

array irt[*] retmo92 retmo93 retmo94 retmo95 retmo96 retmo97 retmo98 retmo99 retmo00 retmo01 retmo02 cutoff;
array tvar[*] t92 t93 t94 t95 t96 t97 t98 t99 t00 t01 t02;
array time[*] time1 time2 time3 time4 time5 time6 time7 time8 time9 time10 time11;

%beginex();
do i=1 to DIM(irt)-1;
do j=1 to DIM(tvar);
	tvar[j]=0;
end;

tvar[i]=1;
period=i;


/*===========================INCLUSION & EXCLUSION CRITERIA==============================*/

*SKIP Each Questionnaire Period with Missing PARITY Data (PAR=.);
*SKIP Each Questionnaire Period with Missing/Invalid FFQ Data (d91=.);
	if nblnk91n>70 then miss91=1; 
	if nblnk95n>70 then miss95=1;
	if nblnk99n>70 then miss99=1;

*SKIP Each Year With Missing Main Questionnaire; 			/*PPP: Only pregnancies 1993 and later are included*/
	array qform[*] qm93 qm93 qm95 qm95 qm97 qm97 qm99 qm99 qm01 qm01 qm01;

array pregi[*] preg92 preg93 preg94 preg95 preg96 preg97 preg98 preg99 preg00 preg01 preg02;
	
*Include Participants in Each Year with a Reported Pregnancy;
	if sb9293>0 then preg92=1; else preg92=0;			
	if (sb9393>0 or sb9395>0) then preg93=1; else preg93=0;
	if (sb9493>0 or sb9495>0) then preg94=1; else preg94=0;
	if (sb9595>0 or sb9597>0) then preg95=1; else preg95=0;
	if (sb9695>0 or sb9697>0) then preg96=1; else preg96=0;
	if (sb9797>0 or sb9799>0) then preg97=1; else preg97=0;
	if (sb9897>0 or sb9899>0) then preg98=1; else preg98=0;
	if (sb9999>0 or sb9901>0) then preg99=1; else preg99=0;
	if (sb0099>0 or sb0001>0) then preg00=1; else preg00=0;
	if sb0101>0 then preg01=1; else preg01=0;
	if sb0201>0 then preg02=1; else preg02=0;


*Chronic Disease Prior to Pregnancy;
	array dbchron[*] db92 db93 db94 db95 db96 db97 db98 db99 db00 db01 db02; 
	array cachron[*] ca92 ca93 ca94 ca95 ca96 ca97 ca98 ca99 ca00 ca01 ca02;
	array cvchron[*] cv91 cv91 cv93 cv93 cv95 cv95 cv97 cv97 cv99 cv99 cv01;

	if (0<dmdtdx<=irt[i] and type=2 and probabil in(1,2)) then dbchron[i]=1; else dbchron[i]=0;
	if (0<dmdtdx<=retmo91 and type=2 and probabil in(1,2)) then db91=1; else db91=0;
	
	if 0<cadtdx<=irt[i] then cachron[i]=1; else cachron[i]=0;
	if 0<cadtdx<=retmo91 then ca91=1; else ca91=0;

	if (mi89=1 or str89=1 or mi91=1 or str91=1 or ang91=1) then cv91=1; else cv91=0;
	if (cv91=1 or mi93=1 or str93=1 or ang91=1) then cv93=1; else cv93=0;
	if (cv93=1 or mi95=1 or str95=1 or cabg95=1 or ang95=1) then cv95=1; else cv95=0;
	if (cv95=1 or mi97=1 or str97=1 or cabg97=1 or ang97=1) then cv97=1; else cv97=0;
	if (cv97=1 or mi99=1 or str99=1 or cabg99=1 or ang99=1) then cv99=1; else cv99=0;

*Twin Pregnancies this Year;
	if twn9293=1 then twin92=1; else twin92=0;
	if (twn9393=1 or twn9395=1) then twin93=1; else twin93=0;
	if (twn9493=1 or twn9495=1) then twin94=1; else twin94=0;
	if (twn9595=1 or twn9597=1) then twin95=1; else twin95=0;
	if (twn9695=1 or twn9697=1) then twin96=1; else twin96=0;
	if (twn9797=1 or twn9799=1) then twin97=1; else twin97=0;
	if (twn9897=1 or twn9899=1) then twin98=1; else twin98=0;
	if (twn9999=1 or twn9901=1) then twin99=1; else twin99=0;
	if (twn0099=1 or twn0001=1) then twin00=1; else twin00=0;
	if twn0101=1 then twin01=1; else twin01=0;
	if twn0201=1 then twin02=1; else twin02=0;

	array twin[*] twin92 twin93 twin94 twin95 twin96 twin97 twin98 twin99 twin00 twin01 twin02;
	
/*=================================EXPOSURES> DIETARY SCORES=============================*/

*Main Dietary Variables;
	array dietq[*] 			diet91 diet91 diet91 diet91 diet95 diet95 diet95 diet95 diet99 diet99 diet99;
	array mddw[*] 			mddw91 mddw91 mddw91 mddw91 mddw95 mddw95 mddw95 mddw95 mddw99 mddw99 mddw99;
	array mddwq[*] 			mddw91q mddw91q mddw91q mddw91q mddw95q mddw95q mddw95q mddw95q mddw99q mddw99q mddw99q;
	array mddwr[*]			mddw91r mddw91r mddw91r mddw91r mddw95r mddw95r mddw95r mddw95r mddw99r mddw99r mddw99r;
    array fgi3wk[*]   		fgi3wk91 fgi3wk91 fgi3wk91 fgi3wk91 fgi3wk95 fgi3wk95 fgi3wk95 fgi3wk95 fgi3wk99 fgi3wk99 fgi3wk99; 
    array fgi1d[*]    		fgi1d91 fgi1d91 fgi1d91 fgi1d91 fgi1d95 fgi1d95 fgi1d95 fgi1d95 fgi1d99 fgi1d99 fgi1d99; 
    array fgi3wkq[*]      	fgi3wk91q fgi3wk91q fgi3wk91q fgi3wk91q fgi3wk95q fgi3wk95q fgi3wk95q fgi3wk95q fgi3wk99q fgi3wk99q fgi3wk99q; 
    array fgi1dq[*]       	fgi1d91q fgi1d91q fgi1d91q fgi1d91q fgi1d95q fgi1d95q fgi1d95q fgi1d95q fgi1d99q fgi1d99q fgi1d99q;
	array fgi3wkr[*]		fgi3wk91r fgi3wk91r fgi3wk91r fgi3wk91r fgi3wk95r fgi3wk95r fgi3wk95r fgi3wk95r fgi3wk99r fgi3wk99r fgi3wk99r;
	array fgi1dr[*]			fgi1d91r fgi1d91r fgi1d91r fgi1d91r fgi1d95r fgi1d95r fgi1d95r fgi1d95r fgi1d99r fgi1d99r fgi1d99r;
	array ahei10[*] 		ahei10_91 ahei10_91 ahei10_91 ahei10_91 ahei10_95 ahei10_95 ahei10_95 ahei10_95 ahei10_99 ahei10_99 ahei10_99;
	array ahei10c[*]		ahei10_91c ahei10_91c ahei10_91c ahei10_91c ahei10_95c ahei10_95c ahei10_95c ahei10_95c	ahei10_99c ahei10_99c ahei10_99c;
	array ahei10q[*] 		ahei10_91q ahei10_91q ahei10_91q ahei10_91q ahei10_95q ahei10_95q ahei10_95q ahei10_95q ahei10_99q ahei10_99q ahei10_99q;
	array ahei10r[*]		ahei10_91r ahei10_91r ahei10_91r ahei10_91r ahei10_95r ahei10_95r ahei10_95r ahei10_95r ahei10_99r ahei10_99r ahei10_99r;
	array ahei10cq[*]		ahei10_91cq ahei10_91cq ahei10_91cq ahei10_91cq ahei10_95cq ahei10_95cq ahei10_95cq ahei10_95cq ahei10_99cq ahei10_99cq ahei10_99cq;
	array pdqs[*] 			test391 test391 test391 test391 test395 test395 test395 test395  test399 test399 test399;
	array pdqsq[*] 			test391q test391q test391q test391q test395q test395q test395q test395q  test399q test399q test399q;
	array pdqsr[*]			test391r test391r test391r test391r test395r test395r test395r test395r test399r test399r test399r;
 
*MDDW Components (1 Point Increments);

        array mddwstarc[*] starch91a starch91a starch91a starch91a starch95a starch95a starch95a starch95a starch99a starch99a starch99a;
        array mddwlegc[*]  legu91a legu91a legu91a legu91a legu95a legu95a legu95a legu95a legu99a legu99a legu99a;
        array mddwnutc[*]  nut91a nut91a nut91a nut91a nut95a nut95a nut95a nut95a nut99a nut99a nut99a;
        array mddwdaic[*]  dairy91a dairy91a dairy91a dairy91a dairy95a dairy95a dairy95a dairy95a dairy99a dairy99a dairy99a;
        array mddwanic[*]  anipro91a anipro91a anipro91a anipro91a anipro95a anipro95a anipro95a anipro95a anipro99a anipro99a anipro99a;
        array mddweggc[*]  egg91a egg91a egg91a egg91a egg95a egg95a egg95a egg95a egg99a egg99a egg99a;
        array mddwlfvc[*]  lfveg91a lfveg91a lfveg91a lfveg91a lfveg95a lfveg95a lfveg95a lfveg95a lfveg99a lfveg99a lfveg99a;
        array mddwbetc[*]  beta91a beta91a beta91a beta91a beta95a beta95a beta95a beta95a beta99a beta99a beta99a;
        array mddwovegc[*] othveg91a othveg91a othveg91a othveg91a othveg95a othveg95a othveg95a othveg95a othveg99a othveg99a othveg99a;
        array mddwofruc[*] ofruit91a ofruit91a ofruit91a ofruit91a ofruit95a ofruit95a ofruit95a ofruit95a ofruit99a ofruit99a ofruit99a;

*FGI1d Components (1 Point Increments);

        array fgi1dstapc[*]  staple1d91 staple1d91 staple1d91 staple1d91 staple1d95 staple1d95 staple1d95 staple1d95 staple1d99 staple1d99 staple1d99 ;
        array fgi1deggc[*]   egg1d91 egg1d91 egg1d91 egg1d91 egg1d95 egg1d95 egg1d95 egg1d95 egg1d99 egg1d99 egg1d99;
        array fgi1dbetac[*]  betac1d91 betac1d91 betac1d91 betac1d91 betac1d95 betac1d95 betac1d95 betac1d95 betac1d99 betac1d99 betac1d99;
        array fgi1dfrvegc[*] fruveg1d91 fruveg1d91 fruveg1d91 fruveg1d91 fruveg1d95 fruveg1d95 fruveg1d95 fruveg1d95 fruveg1d99 fruveg1d99 fruveg1d99;
        array fgi1dlenug[*]  legnut1d91 legnut1d91 legnut1d91 legnut1d91 legnut1d95 legnut1d95 legnut1d95 legnut1d95 legnut1d99 legnut1d99 legnut1d99;
        array fgi1ddairc[*]  dairy1d91 dairy1d91 dairy1d91 dairy1d91 dairy1d95 dairy1d95 dairy1d95 dairy1d95 dairy1d99 dairy1d99 dairy1d99;
        array fgi1dflesc[*]  flesh1d91 flesh1d91 flesh1d91 flesh1d91 flesh1d95 flesh1d95 flesh1d95 flesh1d95 flesh1d99 flesh1d99 flesh1d99;
        array fgi1dafatc[*]  afat1d91 afat1d91 afat1d91 afat1d91 afat1d95 afat1d95 afat1d95 afat1d95 afat1d99 afat1d99 afat1d99;

*FGI3wk Components (1 Point Increments);

        array fgi3wkstapc[*]  staple3wk91 staple3wk91 staple3wk91 staple3wk91 staple3wk95 staple3wk95 staple3wk95 staple3wk95 staple3wk99 staple3wk99 staple3wk99;
        array fgi3wkeggc[*]   egg3wk91 egg3wk91 egg3wk91 egg3wk91 egg3wk95 egg3wk95 egg3wk95 egg3wk95 egg3wk99 egg3wk99 egg3wk99;
        array fgi3wkbetac[*]  betac3wk91 betac3wk91 betac3wk91 betac3wk91 betac3wk95 betac3wk95 betac3wk95 betac3wk95 betac3wk99 betac3wk99 betac3wk99;
        array fgi3wkfrvegc[*] fruveg3wk91 fruveg3wk91 fruveg3wk91 fruveg3wk91 fruveg3wk95 fruveg3wk95 fruveg3wk95 fruveg3wk95 fruveg3wk99 fruveg3wk99 fruveg3wk99;
        array fgi3wklenug[*]  legnut3wk91 legnut3wk91 legnut3wk91 legnut3wk91 legnut3wk95 legnut3wk95 legnut3wk95 legnut3wk95 legnut3wk99 legnut3wk99 legnut3wk99;
        array fgi3wkdairc[*]  dairy3wk91 dairy3wk91 dairy3wk91 dairy3wk91 dairy3wk95 dairy3wk95 dairy3wk95 dairy3wk95 dairy3wk99 dairy3wk99 dairy3wk99;
        array fgi3wkflesc[*]  flesh3wk91 flesh3wk91 flesh3wk91 flesh3wk91 flesh3wk95 flesh3wk95 flesh3wk95 flesh3wk95 flesh3wk99 flesh3wk99 flesh3wk99;
        array fgi3wkafatc[*]  afat3wk91 afat3wk91 afat3wk91 afat3wk91 afat3wk95 afat3wk95 afat3wk95 afat3wk95 afat3wk99 afat3wk99 afat3wk99;

*AHEI-2010 Components (1 Point Increments);

        array aheirmeatc[*] rmeat91c rmeat91c rmeat91c rmeat91c rmeat95c rmeat95c rmeat95c rmeat95c rmeat99c rmeat99c rmeat99c;
        array aheinutc[*] 	nut91c nut91c nut91c nut91c nut95c nut95c nut95c nut95c nut99c nut99c nut99c;
        array aheissbc[*] 	ssb91c ssb91c ssb91c ssb91c ssb95c ssb95c ssb95c ssb95c ssb99c ssb99c ssb99c;
        array aheivegc[*] 	veg91c veg91c veg91c veg91c veg95c veg95c veg95c veg95c veg99c veg99c veg99c;
        array aheifruc[*] 	fruit91c fruit91c fruit91c fruit91c fruit95c fruit95c fruit95c fruit95c fruit99c fruit99c fruit99c;
        array aheipolyc[*] 	poly91c poly91c poly91c poly91c poly95c poly95c poly95c poly95c poly99c poly99c poly99c;
        array aheitranc[*]  trnss91c trnss91c trnss91c trnss91c trnss95c trnss95c trnss95c trnss95c trnss99c trnss99c trnss99c;
        array aheialcc[*]   alc91c alc91c alc91c alc91c alc95c alc95c alc95c alc95c alc99c alc99c alc99c;
        array aheiomegc[*]  omega91c omega91c omega91c omega91c omega95c omega95c omega95c omega95c omega99c omega99c omega99c;
		array aheiwgc[*]	wg91c wg91c wg91c wg91c wg95c wg95c wg95c wg95c wg99c wg99c wg99c;
		array aheinac[*]	na91c na91c na91c na91c na95c na95c na95c na95c na99c na99c na99c;


*PDQS Components (1 Point Increments);

        array pdqspmeac[*] 	pmeat91s pmeat91s pmeat91s pmeat91s pmeat95s pmeat95s pmeat95s pmeat95s pmeat99s pmeat99s pmeat99s;
        array pdqsnpmeac[*] npmeat91s npmeat91s npmeat91s npmeat91s npmeat95s npmeat95s npmeat95s npmeat95s npmeat99s npmeat99s npmeat99s;
        array pdqsrgraic[*] rgrain91s rgrain91s rgrain91s rgrain91s rgrain95s rgrain95s rgrain95s rgrain95s rgrain99s rgrain99s rgrain99s;
        array pdqslfdaic[*] lfdairy91s lfdairy91s lfdairy91s lfdairy91s lfdairy95s lfdairy95s lfdairy95s lfdairy95s lfdairy99s lfdairy99s lfdairy99s;
        array pdqspotatc[*] potato91s potato91s potato91s potato91s potato95s potato95s potato95s potato95s potato99s potato99s potato99s;
        array pdqssweetc[*] sweet91s sweet91s sweet91s sweet91s sweet95s sweet95s sweet95s sweet95s sweet99s sweet99s sweet99s;
        array pdqsssbc[*]   ssb91s ssb91s ssb91s ssb91s ssb95s ssb95s ssb95s ssb95s ssb99s ssb99s ssb99s;
        array pdqsfishc[*]  fish91s fish91s fish91s fish91s fish95s fish95s fish95s fish95s fish99s fish99s fish99s;
        array pdqspoulc[*]  poul91s poul91s poul91s poul91s poul95s poul95s poul95s poul95s poul99s poul99s poul99s;
		array pdqsnutc[*]   nut91s nut91s nut91s nut91s nut95s nut95s nut95s nut95s nut99s nut99s nut99s;
		array pdqsleguc[*]  legu91s legu91s legu91s legu91s legu95s legu95s legu95s legu95s legu99s legu99s legu99s;
		array pdqseggc[*]   egg91s egg91s egg91s egg91s egg95s egg95s egg95s egg95s egg99s egg99s egg99s; 
		array pdqsliqfc[*]  liqfat91s liqfat91s liqfat91s liqfat91s liqfat95s liqfat95s liqfat95s liqfat95s liqfat99s liqfat99s liqfat99s ;
		array pdqscarrc[*]  carr91s carr91s carr91s carr91s carr95s carr95s carr95s carr95s carr99s carr99s carr99s ;
		array pdqsovegc[*]  othveg91s othveg91s othveg91s othveg91s othveg95s othveg95s othveg95s othveg95s othveg99s othveg99s othveg99s;
		array pdqslfvegc[*] lfveg91s lfveg91s lfveg91s lfveg91s lfveg95s lfveg95s lfveg95s  lfveg95s lfveg99s lfveg99s lfveg99s ;
		array pdqscitr[*]   citr91s citr91s citr91s citr91s citr95s citr95s citr95s citr95s citr99s citr99s citr99s;
		array pdqsofrc[*]   ofruit91s ofruit91s ofruit91s ofruit91s ofruit95s ofruit95s ofruit95s ofruit95s ofruit99s ofruit99s ofruit99s;
		array pdqswgrac[*]  wgrain91s wgrain91s wgrain91s wgrain91s wgrain95s wgrain95s wgrain95s wgrain95s wgrain99s wgrain99s wgrain99s;
		array pdqsfriec[*] faway91s faway91s faway91s faway91s faway95s faway95s faway95s faway95s faway99s faway99s faway99s; 
		array pdqscruc[*]  cruveg91s cru91s cru91s cru91s cru95s cru95s cru95s cru95s cru99s cru99s cru99s;

      	

	
***Probit score******;
mddwpbit=PROBIT(mddwr/15233);
fgi3wkpbit=PROBIT(fgi3wkr/15233);
fgi1dpbit=PROBIT(fgi1dr/15233);	
ahei10pbit=PROBIT(ahei10r/15233);
pdqspbit=PROBIT(pdqsr/15233);


***Continuous score**;
	
	mddwscore=mddw[i];
	fgi3wkscore=fgi3wk[i];
	fgi1dscore=fgi1d[i];
	ahei10score=ahei10[i];
	ahei10cscore=ahei10c[i];
	pdqsscore=pdqs[i];
		
*****Continuous Score - 1SD Increases;
	
	mddwsd= mddwscore/1.37;
	fgi3wksd=fgi3wkscore/ 0.98;
	fgi1dsd=fgi1dscore/ 1.03;
	ahei10sd= ahei10score/10.56;
	ahei10csd= ahei10cscore/11.25;
	pdqssd= pdqsscore/4.75;
	
		
*****Indicator Variables;

	mddwcat=mddwq[i];
	fgi3wkcat= fgi3wkq[i];
	fgi1dcat= fgi1dq[i];
	ahei10cat= ahei10q[i];
	ahei10ccat= ahei10cq[i];
	pdqscat= pdqsq[i];
	
**setting reference quintile to value=10**;
	if mddwcat=0 then mddwcat=10;
	if fgi3wkcat=0 then fgi3wkcat=10;
	if fgi1dcat=0 then fgi1dcat=10;
    if ahei10cat=0 then ahei10cat=10;
    if ahei10ccat=0 then ahei10ccat=10;
    if pdqscat=0 then pdqscat=10;

*****Median Scores for Trend Tests (median value for each score quintile is calculated at baseline);	
	if mddwcat=10 then mddwqm= 2;
	if mddwcat=1 then mddwqm= 3;
	if mddwcat=2 then mddwqm= 4;
	if mddwcat=3 then mddwqm= 5;
	if mddwcat=4 then mddwqm= 6;
	
	if fgi3wkcat=10 then fgi3wkqm= 5;
	if fgi3wkcat=1 then fgi3wkqm= 5.5;
	if fgi3wkcat=2 then fgi3wkqm= 6;
	if fgi3wkcat=3 then fgi3wkqm= 7;
	if fgi3wkcat=4 then fgi3wkqm= 8;
	
	if fgi1dcat=10 then fgi1dqm= 3;
	if fgi1dcat=1 then fgi1dqm= 4;
	if fgi1dcat=2 then fgi1dqm= 4.5;
	if fgi1dcat=3 then fgi1dqm= 5;
	if fgi1dcat=4 then fgi1dqm= 6;
	
	if ahei10cat=10 then ahei10qm= 35;
	if ahei10cat=1 then ahei10qm= 42;
	if ahei10cat=2 then ahei10qm= 48;
	if ahei10cat=3 then ahei10qm= 54;
	if ahei10cat=4 then ahei10qm= 63;

	if ahei10ccat=10 then ahei10cqm= 35.9;
	if ahei10ccat=1 then ahei10cqm= 43.1;
	if ahei10ccat=2 then ahei10cqm= 48.6;
	if ahei10ccat=3 then ahei10cqm= 54.8;
	if ahei10ccat=4 then ahei10cqm= 64.8;

	if pdqscat=10 then pdqsqm= 14;
	if pdqscat=1 then pdqsqm= 18;
	if pdqscat=2 then pdqsqm= 21;
	if pdqscat=3 then pdqsqm= 23.8;
	if pdqscat=4 then pdqsqm= 27;
	
	
*Score Components;

mstarc=mddwstarc[i]; mlegc=mddwlegc[i]; mnutc=mddwnutc[i]; mdaic=mddwdaic[i]; manic=mddwanic[i]; 
meggc=mddweggc[i]; mlfvc=mddwlfvc[i]; mbetc=mddwbetc[i]; mvegc=mddwovegc[i]; mfruc=mddwofruc[i];

f1stac=fgi1dstapc[i]; f1eggc=fgi1deggc[i]; f1betc=fgi1dbetac[i]; f1frvc=fgi1dfrvegc[i];
f1legnut=fgi1dlenug[i]; f1daic=fgi1ddairc[i]; f1flec=fgi1dflesc[i]; f1fatc=fgi1dafatc[i];

f3stac=fgi3wkstapc[i]; f3eggc=fgi3wkeggc[i]; f3betc=fgi3wkbetac[i]; f3frvc=fgi3wkfrvegc[i];
f3legnut=fgi3wklenug[i]; f3daic=fgi3wkdairc[i]; f3flec=fgi3wkflesc[i]; f3fatc=fgi3wkafatc[i];

armeatc=aheirmeatc[i]; anutc=aheinutc[i]; assbc=aheissbc[i]; avegc=aheivegc[i]; afruc=aheifruc[i];
apolyc=aheipolyc[i]; atrnc=aheitranc[i]; aalcc=aheialcc[i]; aomegc=aheiomegc[i]; awgc=aheiwgc [i]; 
anac=aheinac[i];

pmeac=pdqspmeac[i]; pnmeac=pdqsnpmeac[i]; prgrac=pdqsrgraic[i]; plfdaic=pdqslfdaic[i]; ppotatc=pdqspotatc[i];
psweec=pdqssweetc[i]; pssbc=pdqsssbc[i]; pfishc=pdqsfishc[i]; ppoulc=pdqspoulc[i]; pnutc=pdqsnutc[i]; pleguc=pdqsleguc[i];
peggc=pdqseggc[i]; pliqfc=pdqsliqfc[i]; pcarc=pdqscarrc[i]; poveg=pdqsovegc[i]; plfvegc=pdqslfvegc[i]; pcitrc=pdqscitr[i]; 
psofc=pdqsofrc[i];  pwgrac= pdqswgrac[i];  pfric=pdqsfriec[i];  pcruc= pdqscruc[i];


*Standardized scores -transformed to percentiles;
     array mddwp[*]    		mddw91p mddw91p mddw91p mddw91p mddw95p mddw95p mddw95p mddw95p mddw99p mddw99p mddw99p ; 
	 array fgi3wkp[*] 		fgi3wk91p fgi3wk91p fgi3wk91p fgi3wk91p fgi3wk95p fgi3wk95p fgi3wk95p fgi3wk95p fgi3wk99p fgi3wk99p fgi3wk99p ;
	 array fgi1dp[*]		fgi1d91p fgi1d91p fgi1d91p fgi1d91p fgi1d95p fgi1d95p fgi1d95p fgi1d95p fgi1d99p fgi1d99p fgi1d99p ;
 	 array ahei10p[*]		ahei10_91p ahei10_91p ahei10_91p ahei10_91p ahei10_95p ahei10_95p ahei10_95p ahei10_95p  ahei10_99p ahei10_99p ahei10_99p;
  	 array pdqsp[*]			test391p test391p test391p test391p test395p test395p test395p test395p test399p test399p test399p ;


        mddwperc= mddwp[i];
        fgi3wkperc= fgi3wkp[i];
        fgi1dperc= fgi1dp[i];
        ahei10perc= ahei10p[i];
        pdqsperc = pdqsp[i];
      
      	mddw10pt= mddwperc/10; *10-point increase;
      	fgi3wk10pt= fgi3wkperc/10;
      	fgi1d10pt= fgi1dperc/10;
      	ahei10_10pt= ahei10perc/10;
	 	pdqs10pt= pdqsperc/10;  
	
	
	
*Sensitivity analysis: 1 SD for most recent diet only (need to delete cumulative update command);
        mrecent= mddwscore/1.4;
        f3wkrecent= fgi3wkscore/ 1.03;
        f1drecent= fgi1dscore/ 1.08;
		arecent= ahei10score/ 10.9;
		precent= pdqsscore/ 4.8;

/*====================OUTCOME: INCIDENT GESTATIONAL DIABETES MELLITUS===================*/
 
*GDM Ever;
        if dbg89=1 then dbg89e=1; else dbg89e=0;
        if (dbg89e=1 or dbg91=1 or dbgd93=1) then dbg91e=1; else dbg91e=0;
        if (dbg91e=1 or dbg93=1) then dbg93e=1; else dbg93e=0;
        if (dbg93e=1 or dbg95=1) then dbg95e=1; else dbg95e=0;
        if (dbg95e=1 or dbg97=1) then dbg97e=1; else dbg97e=0;
        if (dbg97e=1 or dbg99=1) then dbg99e=1; else dbg99e=0;
        if (dbg99e=1 or dbg01=1) then dbg01e=1; else dbg01e=0;
 
*GDM Incident;
        if (dbg89e=0 and dbg91=1) then dbg91i=1; else dbg91i=0;
        if (dbg91e=0 and dbg93=1) then dbg93i=1; else dbg93i=0;
        if (dbg93e=0 and dbg95=1) then dbg95i=1; else dbg95i=0;
        if (dbg95e=0 and dbg97=1) then dbg97i=1; else dbg97i=0;
        if (dbg97e=0 and dbg99=1) then dbg99i=1; else dbg99i=0;
        if (dbg99e=0 and dbg01=1) then dbg01i=1; else dbg01i=0;
 
*Year case is attributed to, if more than one birth in a two year period, GDM is attributed to first pregnancy;

gdm92=0; gdm93=0; gdm94=0; gdm95=0; gdm96=0; gdm97=0; gdm98=0; gdm99=0; gdm00=0; gdm01=0; gdm02=0;

array gdmyear[*] gdm92 gdm93 gdm94 gdm95 gdm96 gdm97 gdm98 gdm99 gdm00 gdm01 gdm02;
        
        if dbg93i=1 then do;
                if preg92=1 then gdmyear[1]=1;
                else if preg93=1 then gdmyear[2]=1;
                else if preg94=1 then gdmyear[3]=1;
                else gdmyear[2]=.;
                end;
        else if dbg95i=1 then do;
                if preg94=1 then gdmyear[3]=1;
                else if preg95=1 then gdmyear[4]=1;
                else if preg96=1 then gdmyear[5]=1;
                else if preg93=1 then gdmyear[2]=1;
                else if preg92=1 then gdmyear[1]=1;
                else gdmyear[4]=.;
                end;
        else if dbg97i=1 then do;
                if preg96=1 then gdmyear[5]=1;
                else if preg97=1 then gdmyear[6]=1;
                else if preg98=1 then gdmyear[7]=1;
                else if preg95=1 then gdmyear[4]=1;
                else if preg94=1 then gdmyear[3]=1;
                else gdmyear[6]=.;
                end;
        else if dbg99i=1 then do;
                if preg98=1 then gdmyear[7]=1;
                else if preg99=1 then gdmyear[8]=1;
                else if preg00=1 then gdmyear[9]=1;
                else if preg97=1 then gdmyear[6]=1;
                else if preg96=1 then gdmyear[5]=1;
                else gdmyear[8]=.;
                end;
        else if dbg01i=1 then do;
                if preg00=1 then gdmyear[9]=1;
                else if preg01=1 then gdmyear[10]=1;
                else if preg02=1 then gdmyear[11]=1;
                else if preg99=1 then gdmyear[8]=1;
                else if preg98=1 then gdmyear[7]=1;
                else gdmyear[10]=.;
                end;

*GDM Case;
        if gdm92=1 then gdmyr=92;
        else if gdm93=1 then gdmyr=93;
        else if gdm94=1 then gdmyr=94;
        else if gdm95=1 then gdmyr=95;
        else if gdm96=1 then gdmyr=96;
        else if gdm97=1 then gdmyr=97;
        else if gdm98=1 then gdmyr=98;
        else if gdm99=1 then gdmyr=99;
        else if gdm00=1 then gdmyr=10;
        else if gdm01=1 then gdmyr=11;
        else if gdm02=1 then gdmyr=12;
        
        array gdmyri[*] gdm92 gdm93 gdm94 gdm95 gdm96 gdm97 gdm98 gdm99 gdm00 gdm01 gdm02;

        gdmcase=gdmyri[i];
        if (gdm92=1 or gdm93=1 or gdm94=1 or gdm95=1 or gdm96=1 or gdm97=1 or gdm98=1 
                or gdm99=1 or gdm00=1 or gdm01=1 or gdm02=1) then case=1; else case=0;

/*=================================COVARIATES===========================================*/


array agemo[*]      agem91 agem91 agem93 agem93 agem95 agem95 agem97 agem97 agem99 agem99 agem99;
array calor[*] 		calor91n calor91n calor91n calor91n calor95n calor95n calor95n calor95n calor99n calor99n calor99n;
array calq[*] 		cal91q cal91q cal91q cal91q cal95q cal95q cal95q cal95q cal99q cal99q cal99q;
array par[*]		par91 par91 par93 par93 par95 par95 par97 par97 par99 par99 par99;
array smkst[*]		smkdr91 smkdr91 smkdr93 smkdr93 smkdr95 smkdr95 smkdr97 smkdr97 smkdr99 smkdr99 smkdr99;
array mets[*]		act91m act91m act91m act91m act91m act91m act97m act97m act97m act97m act97m;
array sed[*]		sittv91 sittv91 sittv91 sittv91 sittv91 sittv91 sittv97 sittv97 sittv97 sittv97 sittv97;
array alcon[*] 		alco91n alco91n alco91n alco91n alco95n alco95n alco95n alco95n alco99n alco99n alco99n;
array bmicnt[*] 	bmi91 bmi91 bmi93 bmi93 bmi95 bmi95 bmi97 bmi97 bmi99 bmi99 bmi01;
array everoc[*]     everoc91 everoc91 everoc91 everoc91 everoc95 everoc95 everoc95 everoc95 everoc99 everoc99 everoc99;


*Age;

	agemonth =irt[i]-birthday; 
	ageyr= agemonth/12;

	age91=round((retmo91-birthday)/12);

	*Categories Combined for Some Analyses;
	if 0<ageyr<30 then agecat=1;
	else if 30<=ageyr<35 then agecat=2;
	else if 35<=ageyr<40 then agecat=3;
	else if ageyr>=40 then agecat=4;
	else agecat=9;

*Age option 2 (in Months);
        agemo[i]=irt[i]-birthday;
        agemonth1=agemo[i];
        ageyr=agemonth1/12;


*Total Caloric Intake; 
	tei=calor[i];
	if 800<=calor[i]<=3500 then teigood=1;
	else if tei=. then teigood=0; 
	else teigood=0;
	
	teiq=calq[i];
	if teiq=0 then teiq=10; *


*Pre-Pregnancy BMI;
	bmicon=bmicnt[i]; 

	if 10<=bmicnt[i]<=23 then bmicat=10; 
	else if 23<bmicnt[i]<=25 then bmicat=2;
	else if 25<bmicnt[i]<=27 then bmicat=3;
	else if 27<bmicnt[i]<=30 then bmicat=4;
	else if 30<bmicnt[i]<=35 then bmicat=5;
	else if 35<bmicnt[i]<80 then bmicat=6;
	else bmicat=9;

	if 10<=bmicnt[i]<25 then bmigroup=10;
	else if 25<=bmicnt[i]<30 then bmigroup=1;
	else if 30<=bmicnt[i]<80 then bmigroup=2;
	else bmigroup=9;

*Parity;
	if par[i]=0 then parcat=10;
	else if par[i]=1 then parcat=1;
	else if par[i]=2 then parcat=2;
	else if par[i] in(3,4,5,6,7,8) then parcat=3;
	else parcat=9;

*Smoking Status - Current, Former, Never;
	if smkst[i]=1 then smkeverb=10; *never;
	else if smkst[i] in (2,3,4,5,6,7,8) then smkeverb=1; *past;
	else if smkst[i] in(9,10,11,12,13,14,15) then smkeverb=2; *current;
	else smkeverb=10;

*Physical Activity;
	if mets[i]>900 then mets[i]=.;

	if 0<=mets[i]<6.4 then metq=10;
	else if 6.4<=mets[i]<15.4 then metq=2;
	else if 15.4<=mets[i]<31.5 then metq=3;
	else if 31.5<mets[i]<800 then metq=4;
	else metq=9;	
	
*Sedentary TV Time;
	if sed[i] in(1,2) then tv=10;
	else if sed[i]=3 then tv=2;
	else if sed[i]=4 then tv=3;
	else if sed[i]=5 then tv=4;
	else if sed[i] in(6,7,8,9) then tv=5;
	else tv=9;

*Family History of T2DM;
	if (mdb89=1 or fdb89=1) then famdb=1; else famdb=10;

*Alcohol; 
	if alcon[i]=0 then alcocat=10;
	else if 0<alcon[i]<5 then alcocat=2;
	else if 5<=alcon[i]<10 then alcocat=3;
	else if 10<=alcon[i]<15 then alcocat=4;
	else if 15<=alcon[i]<200 then alcocat=5;
	else alcocat=9;

*Categories Combined for Some Analyses;
	if alcon[i]=0 then alcocatb=10;
	else if 0<alcon[i]<15 then alcocatb=1;
	else if 15<=alcon[i]<200 then alcocatb=2;
	else alcocatb=9;


*Oral Contraceptive Use Status - Never, Past, Current;
	if everoc[i]=1 then ocuse=10; 
	else if everoc[i]=2 then ocuse=2; 
	else if everoc[i]=3 then ocuse=3; 
	else ocuse=9; 


*Race/Ethnicity;
	if (seuro89=1 or scand89=1 or ocauc89=1) then race=10; 
	else if afric89=1 then race=2; 
	else if hisp89=1 then race=3; 
	else if asian89=1 then race=4; 
	else if oanc89=1 then race=5; 
	else race=9;

	*Categories Combined for Some Analysis;
	if race=10 then cauc=10;
	else if race in(5,9) then cauc=9;
	else cauc=0;
	

	
*Time Period;
	prdcat=period;
	if prdcat=1 then prdcat=100;

	
*Percent calories from macronutrients;
	carbcal91=(carbo91n*4)/calor91n;
	protcal91=(prot91n*4)/calor91n;
	fatcal91=(tfat91n*9)/calor91n;
	moncal91=(mon91n*9)/calor91n;
	satcal91=(sat91n*9)/calor91n;
	afatcal91=(afat91n*9)/calor91n;

*Smoking for table 1, at baseline;
	if smkdr91=1 then smk91=10; *never;
	else if smkdr91 in (2,3,4,5,6,7,8, 9, 10,11, 12, 13, 14, 15) then smk91=1; *past or current;
	else smk91=9;

*Family History of HTN;
	if (mhbp89=1 or fhbp89=1) then famhtn=1; else famhtn=10;


*Indicator variables for Exposure and Covariates;
	mddw1=0; mddw2=0; mddw3=0; mddw4=0; mddw5=0; 
	if mddwcat=10 then mddw1=1; 
	if mddwcat=1 then mddw2=1; 
	if mddwcat=2 then mddw3=1; 
	if mddwcat=3 then mddw4=1; 
	if mddwcat=4 then mddw5=1;
	
	fgi3wk1=0; fgi3wk2=0; fgi3wk3=0; fgi3wk4=0; fgi3wk5=0;
	if fgi3wkcat=10 then fgi3wk1=1; 
	if fgi3wkcat=1 then fgi3wk2=1; 
	if fgi3wkcat=2 then fgi3wk3=1; 
	if fgi3wkcat=3 then fgi3wk4=1; 
	if fgi3wkcat=4 then fgi3wk5=1; 
	
	
	fgi1d1=0; fgi1d2=0; fgi1d3=0; fgi1d4=0; fgi1d5=0;
	if fgi1dcat=10 then fgi1d1=1;
	if fgi1dcat=1 then fgi1d2=1; 
	if fgi1dcat=2 then fgi1d3=1; 
	if fgi1dcat=3 then fgi1d4=1; 
	if fgi1dcat=4 then fgi1d5=1; 
	

	ahei10_1=0; ahei10_2=0; ahei10_3=0; ahei10_4=0; ahei10_5=0;
	if ahei10cat=10 then ahei10_1=1; 
	if ahei10cat=1 then ahei10_2=1; 
	if ahei10cat=2 then ahei10_3=1; 
	if ahei10cat=3 then ahei10_4=1; 
	if ahei10cat=4 then ahei10_5=1; 
	
	pdqs1=0; pdqs2=0; pdqs3=0; pdqs4=0; pdqs5=0; 
	if pdqscat=10 then pdqs1=1; 
	if pdqscat=1 then pdqs2=1; 
	if pdqscat=2 then pdqs3=1; 
	if pdqscat=3 then pdqs4=1; 
	if pdqscat=4 then pdqs5=1;
	
	
	ager=0; age1=0; age2=0; age3=0; age9=0;
	if agecat=1 then ager=1;
	if agecat=2 then age1=1;
	if agecat=3 then age2=1;
	if agecat=4 then age3=1;
	if agecat=9 then age9=1;
	
	white=0;
    if race=10 then white=1;       * Indicator for white/caucasian;

	teir=0; tei1=0; tei2=0; tei3=0; tei4=0;
	if teiq=10 then teir=1; 
	if teiq=1 then tei1=1; 
	if teiq=2 then tei2=1; 
	if teiq=3 then tei3=1; 
	if teiq=4 then tei4=1;

	parr=0; par1=0; par2=0; par3=0; par9=0;
	if parcat=10 then parr=1; 
	if parcat=1 then par1=1; 
	if parcat=2 then par2=1; 
	if parcat=3 then par3=1;  
	if parcat=9 then par9=1;

	smkr=0; smk1=0; smk2=0; 
	if smkeverb=10 then smkr=1; 
	if smkeverb=1 then smk1=1; 
	if smkeverb=2 then smk2=1;
	

	metr=0; met2=0; met3=0; met4=0; met9=0; 
	if metq=10 then metr=1; 
	if metq=2 then met2=1; 
	if metq=3 then met3=1; 
	if metq=4 then met4=1; 
	if metq=9 then met9=1;

	tvr=0; tv2=0; tv3=0; tv4=0; tv5=0; tv9=0;
	if tv=10 then tvr=1; 
	if tv=2 then tv2=1; 
	if tv=3 then tv3=1; 
	if tv=4 then tv4=1; 
	if tv=5 then tv5=1; 
	if tv=9 then tv9=1;

	alcr=0; alc1=0; alc2=0; alc9=0;
	if alcocatb=10 then alcr=1; 
	if alcocatb=1 then alc1=1; 
	if alcocatb=2 then alc2=1; 
	if alcocatb=9 then alc9=1;

	bmir=0; bmi2=0; bmi3=0; bmi4=0; bmi5=0; bmi6=0; bmi9=0;
	if bmicat=10 then bmir=1; 
	if bmicat=2 then bmi2=1; 
	if bmicat=3 then bmi3=1; 
	if bmicat=4 then bmi4=1;
	if bmicat=5 then bmi5=1; 
	if bmicat=6 then bmi6=1; 
	if bmicat=9 then bmi9=1;

	if bmigroup=1 then bmigroup1=1; else bmigroup1=0;
	if bmigroup=2 then bmigroup2=1; else bmigroup2=0;

	per1=0; per2=0; per3=0; per4=0; per5=0; per6=0; per7=0; per8=0; per9=0; per10=0; per11=0;
    if period=1 then per1=1;
    if period=2 then per2=1;
    if period=3 then per3=1;
	if period=4 then per4=1;
    if period=5 then per5=1;
    if period=6 then per6=1;
    if period=7 then per7=1;
    if period=8 then per8=1;
    if period=9 then per9=1;
    if period=10 then per10=1;
    if period=11 then per11=1;

*Pregnant While Filling Out FFQ?*;
pregFFQ=0;   *1=no, 2=yes*;
if year in (1992,1993,1994,1995) then pregFFQ1=cpreg91; 
if pregFFQ1=1 then pregFFQ=2; else if pregFFQ1=2 then pregFFQ=1;
if year in (1996,1997,1998,1999) then pregFFQ=cpreg95;
if year in (2000,2001,2002) then pregFFQ=cpreg99;



*---------------1 DF Interaction Terms---------------;
    *Nuliparous vs. Parous x Score SD; 
                if parcat=10 then nulpar=1;
                else if parcat>=1 then nulpar=0;
                else nulpar=9;
        
                if nulpar ne 9 then do;
                nulpxm=nulpar*mddwsd;
                nulpxf=nulpar*fgi1dsd;
                nulpxg=nulpar*fgi3wksd;
                nulpxa=nulpar*ahei10sd;
                nulpxac=nulpar*ahei10csd;
                nulpxp=nulpar*pdqssd;
                end;

    *FAMDB x Score SD;
    
    			if famdb=1 then famdbeff=1;
    			else if famdb=10 then famdbeff=0;
    			
                famxm=famdbeff*mddwsd;
                famxf=famdbeff*fgi1dsd; 
                famxg=famdbeff*fgi3wksd;
                famxa=famdbeff*ahei10sd;
                famxac=famdbeff*ahei10csd;
                famxp=famdbeff*pdqssd;
                
    *Age <35 vs. Age>=35 x Score SD; 
                if ageyr<35 then agebin=0; 
                else if ageyr>=35 then agebin=1;

                agexm=agebin*mddwsd; 
                agexf=agebin*fgi1dsd;
                agexg=agebin*fgi3wksd;
                agexa=agebin*ahei10sd;
                agexac=agebin*ahei10csd;
                agexp=agebin*pdqssd;
                
    *Prepregnancy BMI X Score SD;
    			if bmicnt[i]<25 then bmieff=0;
    			else if 25<=bmicnt[i] then bmieff=1;
    
       			bmixm=bmieff*mddwsd; 
                bmixf=bmieff*fgi1dsd;
                bmixg=bmieff*fgi3wksd;
                bmixa=bmieff*ahei10sd;
                bmixac=bmieff*ahei10csd;
                bmixp=bmieff*pdqssd;
    
    *Smoking status X Score SD;
    		if smkeverb=10 OR smkeverb=1 then smkeff=0;
    		else if smkeverb=2 then smkeff=1;
    		
    			smkxm=smkeff*mddwsd; 
                smkxf=smkeff*fgi1dsd;
                smkxg=smkeff*fgi3wksd;
                smkxa=smkeff*ahei10sd;
                smkxac=smkeff*ahei10csd;
                smkxp=smkeff*pdqssd;
    

/*============================EXCLUSIONS AT EACH BIENNIAL RISK-SET======================*/


*1992;
if i=1 then do;
%exclude (exrec eq 1);
%exclude (dbg91e eq 1);				/*exclude prevalent GDM cases*/
%exclude (noyear eq 1);				/*exclude self-reported cases that don't also report a pregnancy in the same period*/
%exclude (ca91 eq 1);				/*exclude prevalent cancer cases*/
%exclude (db91 eq 1);				/*exclude prevalent type 2 diabetes cases*/
%exclude (cvchron[i] eq 1);			/*exclude prevalent cvd event cases*/
%exclude (0 lt dtdth lt irt[i]);	/*death*/
%exclude (diet91 ne 1);				/*no pre-preg FFQ*/
%exclude (twin[i] eq 1, skip=t);	/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);	/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);	/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 	/*skip if unrealistic TEI*/
%exclude (miss91 eq 1, skip=t);		/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);		/*skip if parity is missing*/
%output();
end;

*1993;
else if i=2 then do;
%exclude (gdmyri[i-1] eq 1);		/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);		/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);		/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);			/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);	/*death*/
%exclude (twin[i] eq 1, skip=t);	/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);	/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);	/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t);	/*skip if unrealistic TEI*/
%exclude (miss91 eq 1, skip=t);		/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);		/*skip if parity is missing*/
%output();
end;

*1994;
else if i=3 then do;
%exclude (gdmyri[i-1] eq 1);		/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);		/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);		/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);			/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);	/*death*/	
%exclude (twin[i] eq 1, skip=t);	/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);	/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);	/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t);	/*skip if unrealistic TEI*/
%exclude (miss91 eq 1, skip=t);		/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);		/*skip if parity is missing*/
%output();
end;

*1995;
else if i=4 then do;
%exclude (gdmyri[i-1] eq 1);		/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);		/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);		/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);			/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);	/*death*/	
%exclude (twin[i] eq 1, skip=t);	/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);	/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);	/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 	/*unrealistic TEI*/
%exclude (miss95 eq 1, skip=t);		/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);		/*skip if parity is missing*/
%output();
end;

*1996;
else if i=5 then do;
%exclude (gdmyri[i-1] eq 1);			/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);			/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);			/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);				/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);		/*death*/
%exclude (twin[i] eq 1, skip=t);		/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);		/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);		/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 		/*unrealistic TEI*/
%exclude (miss95 eq 1, skip=t);			/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);			/*skip if parity is missing*/
%output();
end;

*1997;
else if i=6 then do;
%exclude (gdmyri[i-1] eq 1);			/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);			/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);			/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);				/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);		/*death*/
%exclude (twin[i] eq 1, skip=t);		/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);		/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);		/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 		/*unrealistic TEI*/
%exclude (miss95 eq 1, skip=t);			/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);			/*skip if parity is missing*/
%output();
end;

*1998;
else if i=7 then do;
%exclude (gdmyri[i-1] eq 1);			/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);			/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);			/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);				/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);		/*death*/
%exclude (twin[i] eq 1, skip=t);		/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);		/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);		/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 		/*unrealistic TEI*/
%exclude (miss95 eq 1, skip=t);			/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);			/*skip if parity is missing*/
%output();
end;

*1999;
else if i=8 then do;
%exclude (gdmyri[i-1] eq 1);			/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);			/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);			/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);				/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);		/*death*/
%exclude (twin[i] eq 1, skip=t);		/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);		/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);		/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 		/*unrealistic TEI*/
%exclude (miss99 eq 1, skip=t);			/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);			/*skip if parity is missing*/
%output();
end;

*2000;
else if i=9 then do;
%exclude (gdmyri[i-1] eq 1);			/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);			/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);			/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);				/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);		/*death*/
%exclude (twin[i] eq 1, skip=t);		/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);		/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);		/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 		/*unrealistic TEI*/
%exclude (miss99 eq 1, skip=t);			/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);			/*skip if parity is missing*/
%output();
end;

*2001;
else if i=10 then do;
%exclude (gdmyri[i-1] eq 1);			/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);			/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);			/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);				/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);		/*death*/
%exclude (twin[i] eq 1, skip=t);		/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);		/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);		/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 		/*unrealistic TEI*/
%exclude (miss99 eq 1, skip=t);			/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);			/*skip if parity is missing*/
%output();
end;

*2002;
else if i=11 then do;
%exclude (gdmyri[i-1] eq 1);			/*censored when they become a case*/
%exclude (dbchron[i-1] eq 1);			/*not included in the cohort if prior type 2 diabetes*/
%exclude (cachron[i-1] eq 1);			/*not included in the cohort if prior cancer*/
%exclude (cvchron[i] eq 1);				/*not included in the cohort if prior cvd event*/
%exclude (0 lt dtdth lt irt[i]);		/*death*/
%exclude (twin[i] eq 1, skip=t);		/*skip if pregnancy was twins*/
%exclude (qform[i] eq 0, skip=t);		/*skip if no main questionnaire*/
%exclude (pregi[i] ne 1, skip=t);		/*skip if no pregnancy reported in this questionnaire period*/
%exclude (teigood ne 1, skip=t); 		/*unrealistic TEI*/
%exclude (miss99 eq 1, skip=t);			/*skip if missing too many FFQ variables*/
%exclude (par[i] eq ., skip=t);			/*skip if parity is missing*/
%output();
end;


end;
%endex();




/*==============Analysis: Correlations between dietary pattern scores===================*/

proc sort data=NEW1; by id; run;

data BASELINE; set NEW1;
by id; if first.id then output;
proc sort data=BASELINE; by id; run;

*Correlation of dietary scores at baseline; 
proc corr data=BASELINE SPEARMAN; var mddw91 fgi3wk91 fgi1d91 ahei10_91 ahei10_91c test391; run;

*Correlation of dietary scores at baseline, energy-adjusted; 
proc corr data=BASELINE SPEARMAN; var mddw91 fgi3wk91 fgi1d91 ahei10_91 ahei10_91c test391; partial tei; run;

*Correlation of dietary scores at baseline, energy-adjusted; 
proc corr data=BASELINE SPEARMAN; var mddw91 fgi3wk91 fgi1d91 ahei10_91 ahei10_91c test391; partial teiq; run;



/*==========TABLE 2: Baseline characteristics by pre-pregnancy dietary score quintile====*/
    
proc sort data=BASELINE; by mddw91q; run;
	proc means data=BASELINE; var mddw91 veg91m fruit91m redmeat91m dairy91m lfdairy91m  refinedg91m potato91m starch91m poul91m fish91m egg91m nut91m legu91m age91 bmi91 act91m alco91n 
		calor91n carbcal91 protcal91 fatcal91 moncal91 satcal91 afatcal91 trnss91n gl91n gid91n; by mddw91q; run;
	proc freq data=BASELINE; tables cauc par91 smk91 everoc91 famhtn famdb; by mddw91q; run;
	
proc sort data=BASELINE; by fgi3wk91q; run; 
	proc means data=BASELINE; var fgi3wk91 veg91f fruit91f redmeat91f dairy91f lfdairy91f refinedg91f potato91f starch91f poul91f fish91f egg91f nut91f leg91f  age91 bmi91 bmi18 act91m alco91n 
		calor91n carbcal91 protcal91 fatcal91 moncal91 satcal91 afatcal91 trnss91n gl91n gid91n; by fgi3wk91q; run;
	proc freq data=BASELINE; tables cauc par91 smk91 everoc91 famhtn famdb; by fgi3wk91q; run;
 
proc sort data=BASELINE; by fgi1d91q; run; 
	proc means data=BASELINE; var fgi1d91 veg91f fruit91f redmeat91f dairy91f lfdairy91f refinedg91f potato91f starch91f poul91f fish91f egg91f nut91f leg91f age91 bmi91 bmi18 act91m alco91n 
		calor91n carbcal91 protcal91 fatcal91 moncal91 satcal91 afatcal91 trnss91n gl91n gid91n; by fgi1d91q; run;
	proc freq data=BASELINE; tables cauc par91 smk91 everoc91 famhtn famdb; by fgi1d91q; run;

proc sort data=BASELINE; by ahei10_91q; run; 
	proc means data=BASELINE; var ahei10_91 veg91a fruit91a redmeat91a dairy91a lfdairy91a refinedg91a potato91a starch91a poul91a fish91a egg91a nut91a leg91a age91 bmi91 bmi18 act91m alco91n 
		calor91n carbcal91 protcal91 fatcal91 moncal91 satcal91 afatcal91 trnss91n gl91n gid91n; by ahei10_91q; run;
	proc freq data=BASELINE; tables cauc par91 smk91 everoc91 famhtn famdb; by ahei10_91q; run;

proc sort data=BASELINE; by ahei10_91cq; run; 
	proc means data=BASELINE; var ahei10_91c age91 bmi91 bmi18 act91m alco91n 
		calor91n carbcal91 protcal91 fatcal91 moncal91 satcal91 afatcal91 trnss91n gl91n gid91n; by ahei10_91cq; run;
	proc freq data=BASELINE; tables cauc par91 smk91 everoc91 famhtn famdb; by ahei10_91cq; run;

proc sort data=BASELINE; by test391q; run; 
	proc means data=BASELINE; var test391 veg91p fruit91p redmeat91p dairy91p lfdairy91p refinedg91p potato91p starch91p poul91p fish91p egg91p nut91p legu91p age91 bmi91 bmi18 act91m alco91n 
		calor91n carbcal91 protcal91 fatcal91 moncal91 satcal91 afatcal91 trnss91n gl91n gid91n; by test391q; run;
	proc freq data=BASELINE; tables cauc par91 smk91 everoc91 famhtn famdb; by test391q; run;

/*====================TABLE 3 (Crude Analysis)==========================================*/

proc sort data=NEW1; by mddwcat fgi3wkcat fgi1dcat ahei10cat ahei10ccat pdqscat; run;
proc freq data=NEW1; tables gdmcase*mddwcat gdmcase*fgi3wkcat gdmcase*fgi1dcat gdmcase*ahei10cat gdmcase*ahei10ccat gdmcase*pdqscat; run;


/*------Proportion of FFQs in 1991 where women were pregnant------*/

proc freq data=NEW1; tables pregFFQ
							sb91 sb92 sb93 sb94 sb95 sb9597 sb9697 
							sb9797 sb9897 sb9799 sb9899 sb9999 sb0099 
							sb9901 sb0001 sb0101 sb0201; run;

proc means data=NEW1; var
						mddwpbit fgi3wkpbit fgi1dpbit ahei10pbit pdqspbit 
						mddwscore fgi3wkscore fgi1dscore ahei10score pdqsscore
						mddwperc fgi3wkperc fgi1dperc ahei10perc pdqsperc 
						mddw10pt fgi3wk10pt fgi1d10pt ahei10_10pt pdqs10pt
						mddwsd fgi3wksd fgi1dsd ahei10sd ahei10csd pdqssd; run;
		
proc freq data=NEW1; tables
						mddwperc fgi3wkperc fgi1dperc ahei10perc pdqsperc 
						mddw10pt fgi3wk10pt fgi1d10pt ahei10_10pt pdqs10pt
						mddwcat fgi1dcat fgi3wkcat ahei10cat pdqscat 
						mddw91q mddw95q mddw99q 
	 					fgi3wk91q fgi3wk95q fgi3wk99q 
						fgi1d91q fgi1d95q fgi1d99q
 						ahei10_91cq ahei10_91q ahei10_95cq ahei10_95q ahei10_99cq ahei10_99q
  						test391q test395q test399q; run;



proc freq data=NEW1; tables agemonth teir tei1 tei2 tei3 tei4 white parr par1 par2 par3 par9 smkr smk1 smk2 metr 
met2 met3 met4 met9 bmir bmi2 bmi3 bmi4 bmi5 bmi6 bmi9 alcr alc1 alc2 alc9 tvr tv2 tv3 tv4 tv5 tv9; run;

/*P-VALUES GENERATED FOR TABLE 1

data tablem; set NEW1; if mddw91q in(1,2,3) then delete; run;
        proc npar1way data=tablem; class mddw91q; var age91; run;
        proc npar1way data=tablem; class mddw91q; var bmi91 ; run;
        proc npar1way data=tablem; class mddw91q; var bmi91 ; run;
        proc npar1way data=tablem; class mddw91q; var act91m ; run;
        proc npar1way data=tablem; class mddw91q; var alco91n ; run;
        proc npar1way data=tablem; class mddw91q; var calor91n ; run;
        proc npar1way data=tablem; class mddw91q; var carbcal91 ; run;
        proc npar1way data=tablem; class mddw91q; var protcal91 ; run;
        proc npar1way data=tablem; class mddw91q; var fatcal91 ; run;
        proc npar1way data=tablem; class mddw91q; var moncal91 ; run;
        proc npar1way data=tablem; class mddw91q; var satcal91 ; run;
        proc npar1way data=tablem; class mddw91q; var afatcal91 ; run;
        proc npar1way data=tablem; class mddw91q; var trnss91n ; run;
        proc npar1way data=tablem; class mddw91q; var gl91n ; run;
        proc npar1way data=tablem; class mddw91q; var gid91n; run;
        proc freq data=tablem; tables cauc*mddw91q par91*mddw91q smk91*mddw91q everoc91*mddw91q famhtn*mddw91q famdb*mddw91q/ fisher; run;

data tablef; set NEW1; if fgi3wk91q in(1,2,3) then delete; run;
        proc npar1way data=tablef; class fgi3wk91q; var age91; run;
        proc npar1way data=tablef; class fgi3wk91q; var bmi91 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var bmi18 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var act91m ; run;
        proc npar1way data=tablef; class fgi3wk91q; var alco91n ; run;
        proc npar1way data=tablef; class fgi3wk91q; var calor91n ; run;
        proc npar1way data=tablef; class fgi3wk91q; var carbcal91 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var protcal91 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var fatcal91 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var moncal91 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var satcal91 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var afatcal91 ; run;
        proc npar1way data=tablef; class fgi3wk91q; var trnss91n ; run;
        proc npar1way data=tablef; class fgi3wk91q; var gl91n ; run;
        proc npar1way data=tablef; class fgi3wk91q; var gid91n; run;
        proc freq data=tablef; tables cauc*fgi3wk91q par91*fgi3wk91q smk91*fgi3wk91q everoc91*fgi3wk91q famhtn*fgi3wk91q famdb*fgi3wk91q /fisher; run;

data tableg; set NEW1; if fgi1d91q in(1,2,3) then delete; run;
        proc npar1way data=tableg; class fgi1d91q; var age91; run;
        proc npar1way data=tableg; class fgi1d91q; var bmi91 ; run;
        proc npar1way data=tableg; class fgi1d91q; var bmi18 ; run;
        proc npar1way data=tableg; class fgi1d91q; var act91m ; run;
        proc npar1way data=tableg; class fgi1d91q; var alco91n ; run;
        proc npar1way data=tableg; class fgi1d91q; var calor91n ; run;
        proc npar1way data=tableg; class fgi1d91q; var carbcal91 ; run;
        proc npar1way data=tableg; class fgi1d91q; var protcal91 ; run;
        proc npar1way data=tableg; class fgi1d91q; var fatcal91 ; run;
        proc npar1way data=tableg; class fgi1d91q; var moncal91 ; run;
        proc npar1way data=tableg; class fgi1d91q; var satcal91 ; run;
        proc npar1way data=tableg; class fgi1d91q; var afatcal91 ; run;
        proc npar1way data=tableg; class fgi1d91q; var trnss91n ; run;
        proc npar1way data=tableg; class fgi1d91q; var gl91n ; run;
        proc npar1way data=tableg; class fgi1d91q; var gid91n; run;
        proc freq data=tableg; tables cauc*fgi1d91q par91*fgi1d91q smk91*fgi1d91q everoc91*fgi1d91q famhtn*fgi1d91q famdb*fgi1d91q /fisher; run;


data tablea; set NEW1; if ahei10_91q in(1,2,3) then delete; run;
        proc npar1way data=tablea; class ahei10_91q; var age91; run;
        proc npar1way data=tablea; class ahei10_91q; var bmi91 ; run;
        proc npar1way data=tablea; class ahei10_91q; var bmi18 ; run;
        proc npar1way data=tablea; class ahei10_91q; var act91m ; run;
        proc npar1way data=tablea; class ahei10_91q; var alco91n ; run;
        proc npar1way data=tablea; class ahei10_91q; var calor91n ; run;
        proc npar1way data=tablea; class ahei10_91q; var carbcal91 ; run;
        proc npar1way data=tablea; class ahei10_91q; var protcal91 ; run;
        proc npar1way data=tablea; class ahei10_91q; var fatcal91 ; run;
        proc npar1way data=tablea; class ahei10_91q; var moncal91 ; run;
        proc npar1way data=tablea; class ahei10_91q; var satcal91 ; run;
        proc npar1way data=tablea; class ahei10_91q; var afatcal91 ; run;
        proc npar1way data=tablea; class ahei10_91q; var trnss91n ; run;
        proc npar1way data=tablea; class ahei10_91q; var gl91n ; run;
        proc npar1way data=tablea; class ahei10_91q; var gid91n; run;
        proc freq data=tablea; tables cauc*ahei10_91q par91*ahei10_91q smk91*ahei10_91q everoc91*ahei10_91q famhtn*ahei10_91q famdb*ahei10_91q /fisher; run;


data tablep; set NEW1; if test391q in(1,2,3) then delete; run;
        proc npar1way data=tablep; class test391q; var age91; run;
        proc npar1way data=tablep; class test391q; var bmi91 ; run;
        proc npar1way data=tablep; class test391q; var bmi18 ; run;
        proc npar1way data=tablep; class test391q; var act91m ; run;
        proc npar1way data=tablep; class test391q; var alco91n ; run;
        proc npar1way data=tablep; class test391q; var calor91n ; run;
        proc npar1way data=tablep; class test391q; var carbcal91 ; run;
        proc npar1way data=tablep; class test391q; var protcal91 ; run;
        proc npar1way data=tablep; class test391q; var fatcal91 ; run;
        proc npar1way data=tablep; class test391q; var moncal91 ; run;
        proc npar1way data=tablep; class test391q; var satcal91 ; run;
        proc npar1way data=tablep; class test391q; var afatcal91 ; run;
        proc npar1way data=tablep; class test391q; var trnss91n ; run;
        proc npar1way data=tablep; class test391q; var gl91n ; run;
        proc npar1way data=tablep; class test391q; var gid91n; run;
        proc freq data=tablep; tables cauc*test391q par91*test391q smk91*test391q everoc91*test391q famhtn*test391q famdb*test391q /fisher; run;
        
     */   


proc sort data=NEW1; by mddwcat;run;    
Proc means n median; 
var             mddwscore; by mddwcat; run;

proc sort data=NEW1; by fgi3wkcat;run;    
Proc means n median; 
var            fgi3wkscore ; by fgi3wkcat; run;

proc sort data=NEW1; by fgi1dcat;run;    
Proc means n median; 
var            fgi1dscore ; by fgi1dcat; run;

proc sort data=NEW1; by ahei10cat;run;    
Proc means n median; 
var            ahei10score ; by ahei10cat; run;

proc sort data=NEW1; by ahei10ccat;run;    
Proc means n median; 
var            ahei10cscore ; by ahei10ccat; run;

proc sort data=NEW1; by pdqscat;run;    
Proc means n median; 
var            pdqsscore ; by pdqscat; run;

























Reeza
Super User

It doesn't look like you're using the arrays correctly. 

 

Variable i is never set but you assign values. You always need to loop through the values. 

 

There no more Information with the log? It usually has more details. Anyways the log tells you which lines in your code to check based on that submission. Start at first error and fix goimg down. 

Tom
Super User Tom
Super User

I would be more worried about the note about truncation.  Did your data get truncated or your program lines.

If you had a long line that defined an array and the line got truncated so that the ARRAY statement didn't actually execute then you would get invalid array reference.

So if you had these two lines to define the arrays X and MDDWR :

array x long list of names /* semicolon is missing because of truncation */
array mddwr another list of names;

And the first line got truncated so that the semi-colon was missing then instead of MDDWR become the name of an array it will instead be just one of the variables defined in the array X.  So when you later try to use it as the name of an array it is an illegal reference.

ballardw
Super User

Between: "data was collected each 4 years and I need to have them for each year period. This approach works well for other variables.)"

and

array mddwr[*]     mddw91r mddw91r mddw91r mddw91r mddw95r mddw95r mddw95r mddw95r mddw99r mddw99r mddw99r;

 

If you are using an explicit array counter such as do i=1 to 12 then you are going to get out of bounds errors as you only have 3 instances of mddw99r so the array only has 11 elements.

SGic
Calcite | Level 5

Hello and thanks. I do not use an explicit array counter, I simply define variables across those years after arraying them, for instance I do:

***Continuous score**;
mddwscore=mddw[i];
fgi3wkscore=fgi3wk[i];
fgi1dscore=fgi1d[i];
ahei10score=ahei10[i];
ahei10cscore=ahei10c[i];
pdqsscore=pdqs[i];

 

The period is 11 years, not 12 (1991-2001). Thanks a lot!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 2892 views
  • 0 likes
  • 4 in conversation