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

I would like to import the text file, the 2nd column should be all characters. 

 

When i import, as the first record was numeric, the format was numeric and those records with alphabet became . ; may i know how to import the file that the 2nd columns should become characters instead of numeric?

 

Anyone can help? Sample file attached.

1 ACCEPTED SOLUTION
5 REPLIES 5
scb
Obsidian | Level 7 scb
Obsidian | Level 7

I tried the file with more variables...The COL5 and COL6 was incomplete after the import...Any idea? Thanks.

 

data want;
infile 'D:\RenewalCSV1.txt' dlm=';';
input col1 $ col2 $ COL3 $ COL4 $ COL5 $ COL6 $;
run;

 

 

PeterClemmensen
Tourmaline | Level 20

When you say incomplete, do you mean truncated? 🙂 In that case use a length statement.

Reeza
Super User

Your text file either has more than 6 cols or the data is on a single line. 

 

If single line make make sure to use the trailing @@. 

ballardw
Super User

If you do not indicate to SAS that a character variable will exceed 8 characters that is the default length.

You may want to use an INFormat statement to indicate how to read the variable.

It would look something like this:

data want;
   infile 'D:\RenewalCSV1.txt' dlm=';';
   informat Col5 Col6 $50.
   input col1 $ col2 $ COL3 $ COL4 $ COL5 $ COL6 $;
run;

Make the size, 50 in my example, sufficient to hold the longest expected value.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1358 views
  • 2 likes
  • 5 in conversation