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.
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.