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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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