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

help with output statement

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

help with output statement

data scores;

   input name $ score1 score2 score3 team $;

   datalines;

Joe 11 32 76 red

Mitchel 13 29 82 blue

Susan 14 27 74 green

;

run;

data scores1 scores2;

set scores;

if name="Joe" then output scores1;

else output;

run;

Log


NOTE: There were 3 observations read from the data set WORK.SCORES.

NOTE: The data set WORK.SCORES1 has 3 observations and 5 variables.

To my understanding with below article Scores1 should have 1 obs and scores2 should have 2 obs.Help with outputs

NOTE: The data set WORK.SCORES2 has 2 observations and 5 variables.

NOTE: DATA statement used (Total process time):

  real time 0.00 seconds

  cpu time 0.00 seconds

I was using this article from SAS community

Example for Conditionally Writing Observations to Multiple Data Sets

One of the SAS data sets contains tours that are guided by the tour guide Lucas and the other contains tours led by other guides. Writing to multiple data sets is accomplished by doing one of the following: 1 naming both data sets in the DATA statement. 2 selecting the observations using an IF condition 3 using an OUTPUT statement in the THEN and ELSE clauses to output the observations to the appropriate data sets

The following DATA step shows these steps:

options pagesize=60 linesize=80 pageno=1 nodate;

data lucastour othertours; set mylib.arts; if TourGuide = ’Lucas’ then output lucastour; else output othertours;

proc print data=lucastour; title "Data Set with TourGuide = ’Lucas’";  proc print data=othertours; title "Data Set with Other Guides"; run;

The following output displays the results:

   Output 10.7 Creating Two Data Sets with One DATA Step Data Set with TourGuide = ’Lucas’ 1 Land Tour Obs City Nights Cost Budget Guide 1 Paris 8 1680 High Lucas 2 New York 6 . Lucas Data Set with Other Guides 2 Land Tour Obs City Nights Cost Budget Guide 1 Rome 3 750 Medium D’Amico 2 London 6 1230 High Wilson 3 Madrid 3 370 Low Torres


Accepted Solutions
Solution
‎03-25-2015 03:18 PM
Respected Advisor
Posts: 3,124

Re: help with output statement

else output scores2;

will get what you expected. If you don't specify the table names, output goes to EVERY table addressed in the DATA statement.

View solution in original post


All Replies
Solution
‎03-25-2015 03:18 PM
Respected Advisor
Posts: 3,124

Re: help with output statement

else output scores2;

will get what you expected. If you don't specify the table names, output goes to EVERY table addressed in the DATA statement.

Contributor
Posts: 27

Re: help with output statement

but my scores2 gives the correct output...even without that.only scores writes all datalines;It worked .!!!Thanks

Respected Advisor
Posts: 3,124

Re: help with output statement

Exactly. What needs going to 'score1' go to 'score1', what shouldn't go to 'score1' still go to 'score1'; while for 'score2', it is different story . What shouldn't go to 'score2' stop at 'score1'.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 309 views
  • 4 likes
  • 2 in conversation