Hello,
I have some problems with some datasets I obtained from Datastream ( I attach an example).
1) Because Datastream uses NA for missing values, I tried to convert all the variables to numeric (as these were assigned as character ones). However, many observations were assigned a (.) even though there was a value (see for example a4).
2) Secondly, I cannot get the order of the variables correctly. Instead of a1 to a313, I get amixed order.
Anyone can help on this?
Here is the code I used:
proc contents data=have out=vars(keep=name type) noprint;
data vars;
set vars;
if type=2 and name ne 'id';
newname=trim(left(name))||"_n";
options symbolgen;
proc sql noprint;
select trim(left(name)), trim(left(newname)),
trim(left(newname))||'='||trim(left(name))
into :c_list separated by ' ', :n_list separated by ' ',
:renam_list separated by ' '
from vars;
quit;
data test2;
set have;
array ch(*) $ &c_list;
array nu(*) &n_list;
do i = 1 to dim(ch);
nu(i)=input(ch(i),8.);
end;
drop i &c_list;
rename &renam_list;
run;
data new2;set test2; retain a1-a313;run;
I would just skip all that and use a data step to read the file. Note the NUMX informat.
I would just skip all that and use a data step to read the file. Note the NUMX informat.
Many thanks data_null_!
It works fine!
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.