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,
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.
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.
Ok I see. Thank you very much for your help and your attention to my problem.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.