Suppose I have following codes:
data new;
set old;
array old_var_array
..................(codes to be inserted)
..................(codes to be inserted)
..................(codes to be inserted)
..................(codes to be inserted)
..................
..................
Based on number of character variables ( which can be obtained using dim(old_var_array) in the above example), I want to create equal number of new variables (NewVar1-NewVar#ofChar). How can I do this? thanks.
Take a look at the method I suggested in a post the other day:
Take a look at the method I suggested in a post the other day:
Thank you very much.The code you gave to me works perfectly for me
By the way, I find another way that can also do the job. Here is the code (I am not sure if this method is considered professional or not):
data _Null_;
set old;
array stringvar
NumofCVar = dim(stringvar) ;
call SYMPUTX('NumOfCVar',NumOfCVar);
run;
data new;
set old;
array old_var_array
array _NewVar[&NumofCVar] NewVar1-NewVar&NumofCVar;
..............
Looks almost sufficiently professional enough to me for whatever that is worth. However, I would simplify the first step so that you don't read through all of the records. e.g.:
data _Null_;
set have;
if _n_ eq 1 then do;
array stringvar
NumofCVar = dim(stringvar) ;
call SYMPUTX('NumOfCVar',NumOfCVar);
end;
stop;
run;
thanks a lot for suggestion
dictionary tables already contains the number of character variables.
proc sql ;
select num_character
from dictionary.tables
where libname='SASHELP' and memname='CLASS';
quit;
Ksharp
thank you Ksharp. I actually didn't know there exists "dictionary tables". It is such a wonderful tool.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.