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;
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;
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;
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.