BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GN0001
Barite | Level 11

Hello team,

I have:

Proc Sort data= &kpa._this data out=&kpa._thisdata;

by thisVar;

Run;

What does this & sign and the dot sign is?

Regards,

Blue Blue

 

 

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your posted code cannot work.  Most likely you have inserted an extra space or some other extra characters. Note that using the pop-up boxes for inserting code will make your posts easier to read since they will use fixed width fonts.

 

Let's add multiple spaces between the words (tokens) in your statements to make it clearer there is something wrong:

proc   sort   data=   &kpa._this   data   out=   &kpa._thisdata   ;

So if KPA has the value FRED then this code expands to 

proc   sort   data=   FRED_this   data   out=   FRED_thisdata   ;

Now it is very clear that there is an extra word "data" in there.  If we remove the space(s) between THIS and DATA then this call to PROC SORT is going to overwrite the original dataset with the sorted version of the dataset.

View solution in original post

9 REPLIES 9
ChrisNZ
Tourmaline | Level 20

& marks the start of the macro variable KPA and the dot marks the end.

 

If the variable has a value of abc, the line will be transformed to

 

proc sort data=abc_this data  out=abc_thisdata;

GN0001
Barite | Level 11
Hello ChrisNZ,
Do we need an Undescore after dot to separate invoke of a Macro variable?
I searched a lot to see where the Macro variable is created in the code; I just found the call to Macro Variable but no trace of Macro creation.
Regards,
Blue Blue

Blue Blue
ChrisNZ
Tourmaline | Level 20
No. The underscore is not linked to the macro variable.
GN0001
Barite | Level 11
Thanks for the response.
What that is used for? Just part of the name of following item?
Regards,
Blue Blue
Blue Blue
Tom
Super User Tom
Super User

The macro processor is a simple text replacement tool.  Especially when you are only talking about macro variable references, like in your example.  Once the text is replaced the resulting text is passed on to SAS to interpret and run the same as if the resulting text was what the program looked like to begin with.

 

So if you create a macro variable named PREFIX. For example by using a %LET statement.

%let prefix=AAA;

And then reference that macro variable in the middle of some other text in your program:

proc sort data=&prefix._old ....

The after the macro processor has finished processing the text your program will look like:

proc sort data=AAA_old ....

So the underscore in this situation just becomes part of the name of the dataset being sorted.

Tom
Super User Tom
Super User

Your posted code cannot work.  Most likely you have inserted an extra space or some other extra characters. Note that using the pop-up boxes for inserting code will make your posts easier to read since they will use fixed width fonts.

 

Let's add multiple spaces between the words (tokens) in your statements to make it clearer there is something wrong:

proc   sort   data=   &kpa._this   data   out=   &kpa._thisdata   ;

So if KPA has the value FRED then this code expands to 

proc   sort   data=   FRED_this   data   out=   FRED_thisdata   ;

Now it is very clear that there is an extra word "data" in there.  If we remove the space(s) between THIS and DATA then this call to PROC SORT is going to overwrite the original dataset with the sorted version of the dataset.

GN0001
Barite | Level 11
Thanks for this great response.
Blue Blue

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 9 replies
  • 1172 views
  • 4 likes
  • 3 in conversation