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

DATA PDI_HENRIQUE;
INPUT TRAT $@ PDI Dm;
DATALINES;
P3 0.98 4.83
P3 0.99 4.76
P3 0.99 4.77
P3 0.98 4.78
P3 0.99 4.8
P3 0.98 4.73
P3 0.98 4.79
P3 0.99 4.78
P3 0.98 4.75
P3 0.99 4.75
P5 0.99 4.84
P5 0.97 4.77
P5 0.99 4.77

 

And OUTPUT DATA returns with column TRAT OK, but columns PDI and Dm = .

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I see two obvious errors. The first is that you don't have an end to your data step. You need a line with a semi-colon to end the lines of data.  Probably if you are using SAS/Studio then SAS/Studio appended some post processing code after your code and the first semi-colon in that was used by SAS to end the data step, so that one is not causing any great harm.

 

The second is that you are trying to use the @ cursor movement command of the INPUT statement to move to a column defined by the value of the PDI variable, but you have not given that variable any value.  

 

It was surprising to me to see that SAS decided that meant you wanted to move the cursor to the first column on the line. So when it tried to read a numeric value into the variable DM starting in column one of the line it didn't like the letter P that all of the lines start with.

 

I suspect you just need to remove the @ from the INPUT statement.  Then it will read three variables. The first character (max length of 8 bytes) and two as numbers.

DATA PDI_HENRIQUE;
  INPUT TRAT $ PDI Dm;
DATALINES;
P3 0.98 4.83
P3 0.99 4.76
P3 0.99 4.77
P3 0.98 4.78
P3 0.99 4.8
P3 0.98 4.73
P3 0.98 4.79
P3 0.99 4.78
P3 0.98 4.75
P3 0.99 4.75
P5 0.99 4.84
P5 0.97 4.77
P5 0.99 4.77
;
proc print;
run;

Results:

Obs    TRAT     PDI     Dm

  1     P3     0.98    4.83
  2     P3     0.99    4.76
  3     P3     0.99    4.77
  4     P3     0.98    4.78
  5     P3     0.99    4.80
  6     P3     0.98    4.73
  7     P3     0.98    4.79
  8     P3     0.99    4.78
  9     P3     0.98    4.75
 10     P3     0.99    4.75
 11     P5     0.99    4.84
 12     P5     0.97    4.77
 13     P5     0.99    4.77

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

I see two obvious errors. The first is that you don't have an end to your data step. You need a line with a semi-colon to end the lines of data.  Probably if you are using SAS/Studio then SAS/Studio appended some post processing code after your code and the first semi-colon in that was used by SAS to end the data step, so that one is not causing any great harm.

 

The second is that you are trying to use the @ cursor movement command of the INPUT statement to move to a column defined by the value of the PDI variable, but you have not given that variable any value.  

 

It was surprising to me to see that SAS decided that meant you wanted to move the cursor to the first column on the line. So when it tried to read a numeric value into the variable DM starting in column one of the line it didn't like the letter P that all of the lines start with.

 

I suspect you just need to remove the @ from the INPUT statement.  Then it will read three variables. The first character (max length of 8 bytes) and two as numbers.

DATA PDI_HENRIQUE;
  INPUT TRAT $ PDI Dm;
DATALINES;
P3 0.98 4.83
P3 0.99 4.76
P3 0.99 4.77
P3 0.98 4.78
P3 0.99 4.8
P3 0.98 4.73
P3 0.98 4.79
P3 0.99 4.78
P3 0.98 4.75
P3 0.99 4.75
P5 0.99 4.84
P5 0.97 4.77
P5 0.99 4.77
;
proc print;
run;

Results:

Obs    TRAT     PDI     Dm

  1     P3     0.98    4.83
  2     P3     0.99    4.76
  3     P3     0.99    4.77
  4     P3     0.98    4.78
  5     P3     0.99    4.80
  6     P3     0.98    4.73
  7     P3     0.98    4.79
  8     P3     0.99    4.78
  9     P3     0.98    4.75
 10     P3     0.99    4.75
 11     P5     0.99    4.84
 12     P5     0.97    4.77
 13     P5     0.99    4.77

 

costafoh
Calcite | Level 5

@Tom It worked!! Thank you very much!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 458 views
  • 0 likes
  • 2 in conversation