- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please correct me if I am wrong:
/*Scenario:
1. Create a variable, Bonus, that is 5% of Income. If the Bonus is over $7000, create the variable Total that sums Bonus and Income
2. Only output observations with Bonus greater than $7000 to the New dataset, BonusOver7K,
there should be no missing value for the Bonus variable in the data set.
3.what is the value of the variable Total for observation 114?
4. what is the grand total of the variable Total for the entire data set?*/
data work.BonusOver7K;
set Souj.input24;
Bonus=Income*0.5;
where Bonus ne .;
if Bonus>7000 then Total=sum(Bouns,Income);/* I think,#1*/
if Bonus>7000 then output BonusOver7K;/* I think, #2*/
run;
Proc print data=BonusOver7K;
sum Total; /* I think, #4 */
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just a little mistake:
you should multiply by 0.05 to have 5% of the bonus.
You can optimize your code by using ‘do’ ‘end’:
if Bonus>7000 then do;
Total=sum(Bouns,Income);/* I think,#1*/
output BonusOver7K;/* I think, #2*/
End;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
Please review your information about WHERE statements. I would expect that you are getting an ERROR message in your code something like this:
ERROR: Variable Bonus is not on file SOUJ.INPUT24.
Because a WHERE statement can ONLY be used if the variable(s) in the WHERE already exist in the INPUT dataset (in this case SOUJ.INPUT24). And since you are creating BONUS, my assumption is that BONUS does not exist.
Since we do not know what variables you're starting with in SOUJ.INPUT24, it also might be that you DO have BONUS in that input data.
You also have a TYPO here:
if Bonus>7000 then Total=sum(Bouns,Income);
So that is also going to be an issue because I think you meant to create TOTAL by summing BONUS and INCOME, not BOUNS and INCOME.
Remember that if you want to subset based on a variable (or column) you are creating in a program, then you can subset using a syntax construct called a "subsetting IF". Since you did not post any data, this program uses just 6 observations that test all your conditions. Generated values for BONUS fall above 7K and under 7K and one value is missing:
The subsetting IF will act as a "gate" and if an observation fails the test, processing will stop. That means for any observations where calculated Bonus is missing or under 7K, the observation will never get to the creation of TOTAL or the implicit output at the end of the DATA step program.
Hope this helps,
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for both of you @Cynthia_sas @ed_sas_member
for correcting me ... I am still learning