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

I want to check the output of using the input funcion, the following is my codes:

DATA a;
INPUT s ;
s2=input(s,3.0);
DATALINES;
5
6
001
2.3
;
RUN;

it returns a missing value for s2. I can't find the error in my codes, could anyone help me?

2016-08-28_115640.png

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Jim identified the right issue.  To make S a character variable, you could try:

 

input s $;

 

Then just as a learning experience, I would suggest you add to the program and also test:

 

s3 = input(s, 3.1);

View solution in original post

3 REPLIES 3
Jim_G
Pyrite | Level 9

Line 2 of your code:   Input s ;    Makes s a numeric variable.

 

Try on line 3     s2 = put(s,3.0);   * converts s (numeric) to a character variable s2

 

Jim

Astounding
PROC Star

Jim identified the right issue.  To make S a character variable, you could try:

 

input s $;

 

Then just as a learning experience, I would suggest you add to the program and also test:

 

s3 = input(s, 3.1);

Tom
Super User Tom
Super User

Because you are referencing a numeric variable where SAS expects a character value it is automatically converting the number into a character string for you.  It will use the BEST12. format to do this. So your when you read only the first three characters using 3.0 informat your will be reading only the leading spaces of the right aligned 12 character values.

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
  • 1665 views
  • 4 likes
  • 4 in conversation