BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Costasg
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I would just skip all that and use a data step to read the file.  Note the NUMX informat.

data have313;
   infile '~/Have.txt' dsd dlm='09'x firstobs=2 lrecl=2048 stopover;
  
input date:ddmmyy. (a1-a313)(:numx.??);
   format date ddmmyy10.;
  
run;

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19

I would just skip all that and use a data step to read the file.  Note the NUMX informat.

data have313;
   infile '~/Have.txt' dsd dlm='09'x firstobs=2 lrecl=2048 stopover;
  
input date:ddmmyy. (a1-a313)(:numx.??);
   format date ddmmyy10.;
  
run;
Costasg
Calcite | Level 5

Many thanks data_null_!

It works fine!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 772 views
  • 0 likes
  • 2 in conversation