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