data gray;
set gd;
daygra= re_bgn-joindate;
if daygra le 365 and daygra NE . then gra1y= 'Y';
else gra1y ='N';
if daygra le 730 and daydep gt 365 then gra2y = 'Y';
else gra2y ='N';
if daygra le 1096 and daygra gt 730 then gra3y = 'Y';
else dep3='N';
if daydep le 1461 and daygra gt 1096 then gra4y = 'Y';
else gra3y ='N';
run;
%macro demog (dem);
PROC freq DATA=gray;
TITLE "score and &dem";
tables graiy*score &dem*score / norow nocol expected chisq;
RUN;
%do i=1 %to 4;
%end;
%mend;
%demog(age);
%demog(sex);
%demog(edu);
run;
QUIT;
I want to see how many years people can graduate, whether it is related to their demographic features. any advice to fix it? Thanks.
Error message shows the variable, gra1y does not exist, that is not true, i did check the dataset. i also changed the variable name to gra1, gra2 but still it does not work. the error message showed gra1 does not exist
There are a few issues to fix.
First is the position of the %DO statement. It should come before PROC FREQ.
Second is the use of grayiy. It should be gray&i.y instead.
Finally, take a look at the prior DATA step. I'm not sure that the ELSE statements are doing the right thing.
Reread the error and your code.
You our have the letter i, not 1 in your code.
There are a few issues to fix.
First is the position of the %DO statement. It should come before PROC FREQ.
Second is the use of grayiy. It should be gray&i.y instead.
Finally, take a look at the prior DATA step. I'm not sure that the ELSE statements are doing the right thing.
Thank you so much!
If you use a different naming convention for your new variables you can avoid a macro. For example if you use gray+number instead you can use the colon to list all at once.
PROC freq DATA=gray;
TITLE "score and &dem";
tables (gray:)*score &dem*score / norow nocol expected chisq;
run;
mine is gray1y, gray2y
should I first change them to gray1, gray2, then I can use your code to avoid the do loop? Is that what you mean?
Thanks.
Try it and see. The beauty of coding is that you can try things and see if they work and if they don't you can change it.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.