BookmarkSubscribeRSS Feed
Irfanmohammed
Calcite | Level 5

data temp1;

input a b c d$;

datalines;

1 1 1 x

1 1 1 y

1 1 1 z

;

run;

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

mkeintz
PROC Star

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. ;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

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

;

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
  • 3 replies
  • 1747 views
  • 0 likes
  • 4 in conversation