DATA Step, Macro, Functions and more

Import txt to sas

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

Import txt to sas

Dear all,

attached is a sample of my data (my real data has over 100,000 row). when I use sas ->file ->import data wizard, after importing successfully, variable cusip lose the leading zeros,

e.g., the first observation has a cusip =00036020, after import, it cusip =36020,

how could I fix this? (note: I have many observations, so I can't do it manually).

thanks for your time !

Lan

Attachment

Accepted Solutions
Solution
‎12-02-2013 03:19 PM
Super User
Posts: 5,085

Re: Import txt to sas

Another possibility would be to take the already-imported variable and convert the data after the fact:

data want;

   set have;

   cuspid_char = put(cuspid, z8.);

   drop cuspid;

   rename cuspid_char = cuspid;

run;


View solution in original post


All Replies
Super User
Posts: 10,500

Re: Import txt to sas

You have two basic choices, one is to leave cuspid as numeric and assign and appropriate format such as Z8.0 to display with leading zeroes. Or import the data as a string. When proc import runs it generates data step code that appears in the log that can be modified. Either use F4 to recall the code to the program editor or copy from the log. The INFORMAT and FORMAT for your cuspid are likely defaulting to a best32. format. Change those lines to be informat cuspid $8. , remove the $ that will appear after the variable in the INPUT statement, save and run the modified code.

Frequent Contributor
Posts: 102

Re: Import txt to sas

thank you so much!!!!

Lan

Solution
‎12-02-2013 03:19 PM
Super User
Posts: 5,085

Re: Import txt to sas

Another possibility would be to take the already-imported variable and convert the data after the fact:

data want;

   set have;

   cuspid_char = put(cuspid, z8.);

   drop cuspid;

   rename cuspid_char = cuspid;

run;


Frequent Contributor
Posts: 102

Re: Import txt to sas

thank you so much!

Lan

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 231 views
  • 0 likes
  • 3 in conversation