Getting three outputs from the same dataset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Getting three outputs from the same dataset

I want three outputs in one dataset and I also want each output to read from “tourrevenue dataset” and not the previous output.

As you may notice there is no data in third output because it is reading from the previous dataset. I want it to have data from tourrevenue where Vendor = 'World'.

data tourrevenue;

    input Country $ 1-11 LandCost Vendor $ NumberOfBookings;

cards;

France       575 Express  10

Spain        510 World    12

Brazil       540 World     6

India        489 Express   .

Japan        720 Express  10

Greece       698 Express  20

New Zealand 1489 Southsea  6

Venezuela    425 World     8

Italy        468 Express   9

Russia       924 World     6

Switzerland  734 World    20

Australia   1079 Southsea 10

Ireland      558 Express   9

;

Run;

Data Three_outputs;

set tourrevenue;

Disc = 'Data';

Output;

Disc = 'Ori';

IF Vendor = 'Express';

output;

LandCost = 0-LandCost ;

Disc = 'rvs';

IF Vendor = 'World';

output;

Run;

Proc sort data= Three_outputs out=Results;

by Disc;

Run;


Accepted Solutions
Solution
‎06-19-2013 06:29 PM
Super User
Posts: 19,851

Re: Getting three outputs from the same dataset

Posted in reply to sasthebest

There is only ever one dataset being read.

Do you intend to have

if vendor="Express" then output;

rather than two separate lines?

Currently your IF statement will only select Express and then your next IF will never be true. I'm not sure what you're intending to do with the retain statement as well.

I think you're looking for something like (untested)

Data Three_outputs;

set tourrevenue;

IF Vendor = 'Express' then do;;

LandCost = Original_amt ;

Disc = 'Ori';

output;

end;

else if vendor='World' then do;


LandCost = 0-LandCost ;

Disc = 'rvs';

output;

end;

else do;

disc='Data';

output;

end;

Run;

Proc sort data= a out=Results;

by Disc;

Run;

View solution in original post


All Replies
Solution
‎06-19-2013 06:29 PM
Super User
Posts: 19,851

Re: Getting three outputs from the same dataset

Posted in reply to sasthebest

There is only ever one dataset being read.

Do you intend to have

if vendor="Express" then output;

rather than two separate lines?

Currently your IF statement will only select Express and then your next IF will never be true. I'm not sure what you're intending to do with the retain statement as well.

I think you're looking for something like (untested)

Data Three_outputs;

set tourrevenue;

IF Vendor = 'Express' then do;;

LandCost = Original_amt ;

Disc = 'Ori';

output;

end;

else if vendor='World' then do;


LandCost = 0-LandCost ;

Disc = 'rvs';

output;

end;

else do;

disc='Data';

output;

end;

Run;

Proc sort data= a out=Results;

by Disc;

Run;

Super User
Posts: 5,516

Re: Getting three outputs from the same dataset

Posted in reply to sasthebest

You'll need to do a better job explaining your goal here.  The sample code you provided has many flaws, including referring to a data set "a" that doesn't exist, and referring to a variable "original_amt" that doesn't exist.  There are other problems, such as the effects of the IF statement.  You would be better off showing the "after" picture to match the "before" data in your post.  There would be many posters willing to help at that point.

Good luck.

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 148 views
  • 3 likes
  • 3 in conversation