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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

4 REPLIES 4
ballardw
Super User

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.

LanMin
Fluorite | Level 6

thank you so much!!!!

Lan

Astounding
PROC Star

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;


LanMin
Fluorite | Level 6

thank you so much!

Lan

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1012 views
  • 0 likes
  • 3 in conversation