BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
%let student_age=15 ;
proc print data=sashelp.class;
var &student_age _numeric_ ;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

What do you want to do?

Please describe your question clearly.

 

If you want to filter by age, you can do it with where.

%let student_age=15 ;
proc print data=sashelp.class;
  where age=&student_age;
  var _numeric_ ;
run;

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

What do you want to do?

Please describe your question clearly.

 

If you want to filter by age, you can do it with where.

%let student_age=15 ;
proc print data=sashelp.class;
  where age=&student_age;
  var _numeric_ ;
run;
andreas_lds
Jade | Level 19

It seems you forgot to ask a question.

Enabling the option mprint is recommend to see the code that was generated. 

PaigeMiller
Diamond | Level 26

@BrahmanandaRao wrote:
%let student_age=15 ;
proc print data=sashelp.class;
var &student_age _numeric_ ;
run;

There are a number of errors here. One is that you did not ask a question.

 

Another error is that when you use macro variables, and run the code, the value of the macro variable replaces the macro variable itself, and this replacement must produce legal valid working SAS code. Here is your code when I replace the value of the macro variable in place of the macro variable itself.

 

proc print data=sashelp.class;
var 15 _numeric_ ;
run;

So, is this valid legal working SAS code that does what you want? It is not valid working SAS code. Can you see why?

 

When working with macro variables, you must first create code that works without macro variables for one specific value (in this case 15). You did not do that. Since you don't have working code without macro variables, it will never work with macro variables either. Many people ignore this advice ... please don't be one of those people.

 

Last error: your title says you are using a macro, but you are not, you are using a macro variable. Macros and macro variables are not the same thing. Do not call macro variables by the term macro.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 836 views
  • 0 likes
  • 4 in conversation