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.
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!
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.