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;
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.
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.
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
;
HEY THANKS
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.
Ready to level-up your skills? Choose your own adventure.