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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

2 REPLIES 2
Reeza
Super User

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;

Astounding
PROC Star

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

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
  • 622 views
  • 3 likes
  • 3 in conversation