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
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.
& 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;
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.