BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Shailesh_R_T
Calcite | Level 5

DATA TRAILING;
INPUT @6 TYPE$ 1. @;
IF TYPE= '1' THEN INPUT AGE$= 1-2;
ELSE IF TYPE='2' THEN INPUT AGE$= 4-5;
DROP TYPE;
;
DATALINES;
23     1
   44 2
;
PROC PRINT DATA=TRAILING;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Please do not type the TITLE in ALL CAPITAL LETTERS. 

 

Please do not attach files. Include the log and anything else you want to show us in your message, not as file attachments.

 

We requested this from you previously. We will try to help you, but you have to help us as well.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please do not type the TITLE in ALL CAPITAL LETTERS. 

 

Please do not attach files. Include the log and anything else you want to show us in your message, not as file attachments.

 

We requested this from you previously. We will try to help you, but you have to help us as well.

--
Paige Miller
Tom
Super User Tom
Super User

You cannot have the = in the INPUT statement.  Also do not add a space between the $ and rest of the informat specification.  I know SAS accepts it but it just makes your code look broken.  If you just want the INPUT statement to read one character from column 6 you can also just use column mode for that variable also.

 

And you are apparently not reading the right columns for the TYPE variable.  The values appear in columns 8 and 7 in your example data, not column 6.

 

I do not understand why you need to run different INPUT statements for the example data you show.  Why not just read AGE from columns 1 to 5 ?  That will work fine for your example data.


1    data trailing;
2      input age 1-5 type $ ;
3      list;
4    datalines;

RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+--
5          23     1
6             44 2
NOTE: The data set WORK.TRAILING has 2 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.00 seconds

Is the problem that your lines of data have accidentally had some of the spaces replaced by TAB characters?  If so you might want to add an INFILE statement so that you can add the EXPANDTABS option.  You might also want the TRUNCOVER option in case the lines are truncated.

data trailing;
  infile datalines expandtabs truncover;
  input age 1-5 type $ ;
datalines;
23     1
   44 2
;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 772 views
  • 1 like
  • 3 in conversation