BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10
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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

6 REPLIES 6
Reeza
Super User

Reread the error and your code. 

 

You our have the letter i, not 1 in your code. 

Astounding
PROC Star

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.

Reeza
Super User

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;
Bal23
Lapis Lazuli | Level 10

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.

Reeza
Super User

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.

sas-innovate-2024.png

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.

 

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
  • 6 replies
  • 1762 views
  • 1 like
  • 3 in conversation