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

Dear Sas experts, 

 

I am trying to create a simple dataset with 2 char variables, one of each is actually a long string with unpredicted length. 

 

data myLine;
infile datalines delimiter='|';
input myLine $75. lineType $20.;
datalines;
L1. This is my very long line of unpredicted length. | line_one
L2. This is my second very long line of unpredicted length.| line_simple
L3. This is my third, third, third very long line of unpredicted length.| line_another
;
run;

 

However, the dataset looks weird, e.g. 

 

myLine                                                                              lineType

This is my very long line of unpredicted length. | line         one

 

The results really depends on the length of the first column (myLine). The numbers .75 and .20 are arbitrary. When I put no numbers (just $) the lines are cut after 8 symbols, I believe. 

 

What is the right way to allow unlimited length (or at least limited by 200 symbols) for the line and to create reliable column values. 

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
input myLine $75. lineType $20.;

This is called formatted input. SAS will read exactly the number of characters into a column that are specified, regardless of delimiters.

If you want to specify maximum lengths for strings, but have variable lengths in the data (and want to honor the delimiters), do this:

informat myLine $75. lineType $20.;
input myLine lineType;

View solution in original post

3 REPLIES 3
Reeza
Super User

Use informats to specify the maximum length possible. Yes, the default length for a SAS character variable is 8. 

 

data myLine;
informat myline $200. lineTYpe $20.;
infile datalines delimiter='|';
input myLine lineType ;
datalines;
L1. This is my very long line of unpredicted length. | line_one
L2. This is my second very long line of unpredicted length.| line_simple
L3. This is my third, third, third very long line of unpredicted length.| line_another
;
run;
Kurt_Bremser
Super User
input myLine $75. lineType $20.;

This is called formatted input. SAS will read exactly the number of characters into a column that are specified, regardless of delimiters.

If you want to specify maximum lengths for strings, but have variable lengths in the data (and want to honor the delimiters), do this:

informat myLine $75. lineType $20.;
input myLine lineType;
braverju
Obsidian | Level 7
Thank you! Got it now. 🙂

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
  • 3 replies
  • 7465 views
  • 2 likes
  • 3 in conversation