Learning SAS? Welcome to the exclusive online community for all SAS learners.

Error on SAS Studio

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Error on SAS Studio

I'm trying test the program bellow on SAS Studio:

 

data red_team;
input Team $ 13-18 @;
if Team='red';
input IdNumber 1-4 StartWeight 20-22 EndWeight 24-26;
datalines;
1023 David red 189 165
1049 Amelia yellow 145 124
1219 Alan red 210 192
1246 Ravi yellow 194 177
1078 Ashley red 127 118
1221 Jim yellow 220 .
;
proc print data=red_team;
title 'Red Team';
run;

 

I got it from Step-by-step Programam with Base SAS 9.4.

 

The program runs without error message but any data is loaded.

 

Could you please help me?

 

Thanks.


Accepted Solutions
Solution
‎02-05-2018 06:50 AM
Super User
Super User
Posts: 9,840

Re: Error on SAS Studio

Hi,

 

It something to do with your pointers, i.e. you read in team up to 18, so that is where the pointer is for the next read, so the data never reads in correctly.  I don't have time to correct it, as its simpler to just use:

data red_team;
   input idnumber name $ team $ startweight endweight;
   if Team='red';
datalines;
1023 David red 189 165
1049 Amelia yellow 145 124
1219 Alan red 210 192
1246 Ravi yellow 194 177
1078 Ashley red 127 118
1221 Jim yellow 220 .
;
run;

Note how I use lower case in my coding, and I finish the block with a run; This uses the default one space delimiter to read in the data, sufficient for your needs.

View solution in original post


All Replies
Solution
‎02-05-2018 06:50 AM
Super User
Super User
Posts: 9,840

Re: Error on SAS Studio

Hi,

 

It something to do with your pointers, i.e. you read in team up to 18, so that is where the pointer is for the next read, so the data never reads in correctly.  I don't have time to correct it, as its simpler to just use:

data red_team;
   input idnumber name $ team $ startweight endweight;
   if Team='red';
datalines;
1023 David red 189 165
1049 Amelia yellow 145 124
1219 Alan red 210 192
1246 Ravi yellow 194 177
1078 Ashley red 127 118
1221 Jim yellow 220 .
;
run;

Note how I use lower case in my coding, and I finish the block with a run; This uses the default one space delimiter to read in the data, sufficient for your needs.

Occasional Contributor
Posts: 7

Re: Error on SAS Studio

Thanks, it works fine for me!

Super User
Posts: 10,574

Re: Error on SAS Studio

[ Edited ]

Your datalines do not match the positions specified in the input statements, see this corrected code:

data red_team;
input Team $ 13-18 @;
if Team='red';
input IdNumber 1-4 StartWeight 20-22 EndWeight 24-26;
datalines;
1023 David  red    189 165
1049 Amelia yellow 145 124
1219 Alan   red    210 192
1246 Ravi   yellow 194 177
1078 Ashley red    127 118
1221 Jim    yellow 220 .
;
run;

proc print data=red_team;
title 'Red Team';
run;

When posting code, use the proper buttons, as advised in https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce.

The main posting window changes formatting (removes blanks etc).

Use the {i} button for logs or other non-SAS-code text.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 318 views
  • 0 likes
  • 3 in conversation