hello,
I created a macro variable in this way:
proc sql;
select NAME
into :totale separated by ' '
from contenst;
quit;
The log of '%put &totale;' is:
LDL PAD PAS age altezza birth_date bmi
This is the window that I wrote:
%window info
#5 @5 'these are the variable of your dataset:'
#8 @5 "&totale"
#5 @60 'enter the variable you want to keep'
#7 @60 'names:' +1 newtot 600 attr=underline display=yes;
%display info;
With this program I see 'LDL PAD PAS age altezza birth_date bmi' in a row, but I would like to display them in a column, in this way:
these are the variable of your dataset:
LDL
PAD
PAS
age
...
how can I do?
I agree 1000% that you need a set of macro variables instead of 1. However, I would change the interaction and requirements to make life easier for the user and to eliminate spelling mistakes. For example:
%window info #5 @5 'these are the variable of your dataset:' #8 @5 keep1 1 attr=underline display=yes @8 "&totale1" / @5 keep2 1 attr=underline display=yes
@8 "&totale2"
/ @5 keep3 1 attr=underline display=yes @8 "&totale3"
/ @......
#5 @60 'Put a "K" before each variable that you want to keep' ;
Do you know how to get separate macro variables instead of one long one?
Forward slash will write to next line, but you need to define separate macros to put them in separate lines
%let totale1=LDL;
%let totale2=PAD;
%let totale3=PAS;
%let totale4=age;
%let totale5=altezza;
%let totale6=birth_date;
%let totale7=bmi;
%window info
#5 @5 'these are the variable of your dataset:'
#8 @5 "&totale1"
/ @5 "&totale2"
/ @5 "&totale3"
/ @5 "&totale4"
/ @5 "&totale5"
/ @5 "&totale6"
/ @5 "&totale7"
#5 @60 'enter the variable you want to keep'
#7 @60 'names:' +1 newtot 600 attr=underline display=yes;
%display info;
I agree 1000% that you need a set of macro variables instead of 1. However, I would change the interaction and requirements to make life easier for the user and to eliminate spelling mistakes. For example:
%window info #5 @5 'these are the variable of your dataset:' #8 @5 keep1 1 attr=underline display=yes @8 "&totale1" / @5 keep2 1 attr=underline display=yes
@8 "&totale2"
/ @5 keep3 1 attr=underline display=yes @8 "&totale3"
/ @......
#5 @60 'Put a "K" before each variable that you want to keep' ;
Do you know how to get separate macro variables instead of one long one?
I don't know how to create one macro variable for each name. I have a dataset and I have to create for each variable of the dataset a macro variable. How can I do?
Similar to what you did in the first place, to create a separate macro variable holding each variable's name:
proc sql;
select name into : totale1 - : totale99 from contents;
quit;
My recollection (can't test it right now) is that this creates only as many macro variables as needed. I'm assuming that 99 variables is more than enough, since you won't be able to display that many in a single window.
I'm also concerned that you won't be able to use the results later, since it may require additional skills with macro language. But you will have to be the judge of that.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: