Hi,
Wondering if anybody can help me re the following, please.
I have to create a macro code for a demography table for at least 50 variables,
At the moment, I am assigning a sequence number to each variable separately but I think there is a way through proc sql or do loop, to create a list of all variables and then assign a number next to it as store it as a macro variable?
Many thanks,
@Sami1234 wrote:
I have to create a macro code for a demography table for at least 50 variables,
At the moment, I am assigning a sequence number to each variable separately but I think there is a way through proc sql or do loop, to create a list of all variables and then assign a number next to it as store it as a macro variable?
The words are not entirely clear to me. Could you give a brief example with three variables of what the starting point is, and what the end result is that you want?
Hi,
Thanks for replying.
I would like to create a list of macro variables associated with each required variable in the dataset. i.e. age=1, sex=2, bmi=3.
I can put the list of sorting variables, for example, sortlist=age, sex, bmi and then it should create macro variables associated with this sort. Would it be possible?
Thanks,
Again, I'm not following your explanation, and an example (with 3 or 4 variables) would help.
Hi,
For example, I would like to input a variable list in the proc SQL or loop and would like to create a macro numeric variable associated with it.
Below is the pseudo code
varlist=(var1, var2 , var3 ...etc)
proc sql noprint;
create table seq as
select var(i) from varlist as seq(i);
quit;
I'm still not 100% sure I understand, but maybe this is what you are asking for:
%macro dothis;
%let varlist=var1 var2 var3;
%do i = 1 %to %sysfunc(countw(&varlist));
%let seq&i = %scan(&varlist,&i,%str( ));
%end;
%put &=seq1 &=seq2 &=seq3;
%mend;
%dothis
If that's not it, don't write more words, because I am not understanding. SHOW ME. Show me the inputs, show me the outputs. Don't just show me the inputs and then assume I know what you want. You have to show me both the inputs and the outputs.
No idea what you mean. I have done thousands of Demography datasets and outputs (and other domains) and never had to assign a number to each value? I think your probably misunderstanding, or overthinking your original problem, which you haven't told us about. Note SDTM does not include formats, but you could create them internally for an output if really needed.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.