BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data dup;
input id city$;
cards;
1 hyd
2 blg
2 chn
3 hyd
3 gurg
4 mumb
;
run;




%let Req_id=4;
proc print data=dup noobs;
where id='&Req_id';
run;

Here I have sample table then i defined macro variable Req_id; to get required id 

but above code shows error

Anandkvn_0-1607312306633.png

 

 

 

5 REPLIES 5
mkeintz
PROC Star

Two issues:

 

  1. The macro process will pass on the quotes, so the regular sas language compiler will see those quotes and presume you expect ID to be a character variable.

  2. But even if ID were a character variable here, your program would fail to find an observation.  This is because there is an important relationship between the macro interpreter and single quotes vs double quotes.  Namely, the macro interpreter will not attempt to resolve the macrovar value inside single quotes, but will resolve text inside double quotes.   If ID were a character variable, you would need to use double quotes.  
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
BrahmanandaRao
Lapis Lazuli | Level 10
solution please
PaigeMiller
Diamond | Level 26

First, get this code to work WITHOUT macro variables. You have not done this. Once you get it to work without macro variables, then it will be easy to get it to work WITH macro variables. If you can't get it to work WITHOUT macro variables, then it will never work WITH macro variables. 


The above is the process you ought to follow for any attempt to use macro variables or macros.


Show us working code WITHOUT macro variables.

--
Paige Miller
Tom
Super User Tom
Super User

The macro processor ignores & and % inside of single quotes. So the macro processor ignored this line.

where id='&Req_id';

so you tried to compare the value if ID to ampersand followed by letters Req_id.

 

Since you defined ID as numeric you want to write a line like this:

where id=4;

So how should you change the line of code to have that text generated by the macro processor?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 504 views
  • 0 likes
  • 5 in conversation