If I create one variable list like this,
%let varlist=c1-c9;
How to get the number of variables in &varlist?
If I %let n=%sysfunc(countw(&varlist)), &n will be 2.
Any way to get the exact number of variables in &varlist?
Thanks!
Second way :
%let varlist=c1-c9; data _null_; array a{*} &varlist; call symputx('n',dim(a)); stop; run; %put &n ;
Ksharp
How about :
%let varlist=c1-c9;
%let start=%scan(&varlist,1, ,kd);
%let end=%scan(&varlist,-1, ,kd);
%let n=%eval(&end-&start+1) ;
%put &n ;
Ksharp
Second way :
%let varlist=c1-c9; data _null_; array a{*} &varlist; call symputx('n',dim(a)); stop; run; %put &n ;
Ksharp
Thank you, Ksharp!
Another question.
%let varlist=c1-c4 d1 d9;
How can I get the variable name list like c1 c2 c3 c4 d1 d9?
Thanks!
proc transpose data=have(obs=0) out=varlist;
var c1 c2 ..... ; * any list of variables that exist in have;
run;
You get a SAS data set and you can use it to answer all kinds of questions including how many.
Acutally NULL has already given you a good solution.
%let varlist=c1-c4 d1 d9; data _null_; length list $ 200; array a{*} &varlist; do i=1 to dim(a); list=catx(' ',list,vname(a{i})); end; call symputx('list',list); stop; run; %put &list ;
Ksharp
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 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.