data temp1;
input a b c d$;
datalines;
1 1 1 x
1 1 1 y
1 1 1 z
;
run;
I am sorry, your question is not clear. Also note your test data is incorrect (typo in datalines, column d is never read in).
There are defaults in SAS, as you have not supplied $ in the input line, then the data defaults to numeric, although the final column would not as it is character.
What do you mean by "separate".? Your program, (after correction of spelling in datalines statement) as it stands, reads three numeric vars, and ignores the 4th data item in each line of data.
If you want to read the 4th field, you need a 4th varname in the input statement, along with an input format to tell sas it is a character variable.
input a b c d $1. ;
Please be a bit more specific on your question. What do you mean my "separate"?
If you mean make a varaible numeric or character the way the variable is created will set whether it is numeric or character. By default most variables will be numeric. SAS does not have any "mixed" type. A variable is either numeric or character. If you want to see the character values the variable must be character.
In a simple example such as you provide using $ after the variable name will tell SAS to read the last column as character. The default when done this way will hold a maximum of 8 characters. If you specify an INFORMAT or LENGTH statement for the varaible before use you can set the length longer to hold a longer value.
data temp1;
input a b c letter $;
datallines;
1 1 1 x
1 1 1 y
1 1 1 z
;
run;
data temp1;
Length letter $ 25; /*<= set maximumn number of characters a variable will hold to 25*/
input a b c letter $;
datalines; /*<= corrected spelling*/
1 1 1 x
1 1 1 y
1 1 1 z
2 2 2 Amuchlongerstring
;
run;
or
data temp1;
informat letter $25. ; /*<=read variable using 25 characters*/
input a b c letter $;
datalines;
1 1 1 x
1 1 1 y
1 1 1 z
2 2 2 Amuchlongerstring
;
run;
Also you can enclose a value in single or double quotes in an assignment statement
data temp1;
informat letter $25. ; /*<=read variable using 25 characters*/
input a b c letter $;
anothervar = 'This is a different string value'; /*<= note that when using this approach without a Length statement the length will the that of the first value encountered in the code in this case 32*/
datalines;
1 1 1 x
1 1 1 y
1 1 1 z
2 2 2 Amuchlongerstring
;
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.