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

Hi,

 

SAP version 9.4



Data file (data.txt)

George
Albert
Bob


My SAS program to read the data above:

DATA Work.names;
	INFILE 
		'/folders/myfolders/exercices/data/data.txt'
		missover
	;
	INPUT name :$ 6.;
RUN;
PROC PRINT DATA = Work.names;
TITLE 'Names';
RUN;


It seems to me that:

INPUT name :$ 6.;

And (putting the colon after the $ character)

INPUT name $: 6.;

Both give the same result. As I'm a beginner I just wanted to know why. Is it just the fact that both syntaxes are accepted by SAS or there is some concept that I've missed?

 

Thanks in advance,

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

As you have seen, both work.

 

The order doesn't matter much because the colon is instructions for reading in the variable, but the dollar sign is defining characteristics of the variable.  So they don't really conflict  

 

SAS is pretty flexible in defining characteristics of a variable.  This combination should also work:

 

length name $ 6;
input name : 6.;

The one thing that doesn't work is re-defining the length of a character variable after the fact.  This would give an error:

 

input name $;
length name $ 6;

The INPUT statement would assign NAME a length of 8, and a later LENGTH statement can't change that.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

As you have seen, both work.

 

The order doesn't matter much because the colon is instructions for reading in the variable, but the dollar sign is defining characteristics of the variable.  So they don't really conflict  

 

SAS is pretty flexible in defining characteristics of a variable.  This combination should also work:

 

length name $ 6;
input name : 6.;

The one thing that doesn't work is re-defining the length of a character variable after the fact.  This would give an error:

 

input name $;
length name $ 6;

The INPUT statement would assign NAME a length of 8, and a later LENGTH statement can't change that.

Odyssey2001
Fluorite | Level 6

Ok I see. Thank you very much for your help and your attention to my problem.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 556 views
  • 1 like
  • 2 in conversation