i'm confusing in this question , and how to subtract ?
please help me out.
Run a single SQL program to update the values of variables. Add 5 more with weight if Type is Hamburger and subtract 100 from Calories.
The code works for me. You didn't include enough of your SAS log for us to see what error you might have made.
data food;
length type $20 weight calories 8;
input type weight calories ;
cards;
Hamburger 20 500
Hamburger 24 600
Chips 5 1000
;
proc print data=food;
title 'BEFORE';
run;
proc sql;
update FOOD
set weight=weight+5
, calories=calories-100
where type='Hamburger'
;
quit;
proc print data=food;
title 'AFTER';
run;
BEFORE Obs type weight calories 1 Hamburger 20 500 2 Hamburger 24 600 3 Chips 5 1000 AFTER Obs type weight calories 1 Hamburger 25 400 2 Hamburger 29 500 3 Chips 5 1000
Re: "subtract":
In your select expression, you need to reduce the value of the calories field by 100. I.e., you are being asked not only to list a bunch of fields from a table, but also to introduce a mathematical expression that would change the value of calories.
@Abhau wrote:
i'm confusing in this question , and how to subtract ?
please help me out.
Run a single SQL program to update the values of variables. Add 5 more with weight if Type is Hamburger and subtract 100 from Calories.
What I normally do on a test where the question is written in a confusing way is make an assumption about what they mean and explain clearly what question I am actually going to answer and then answer the clarified question.
So in this case if the question means:
Given a dataset name FOOD with character variable TYPE and numeric variables WEIGHT and CALORIES write a program using the SQL UPDATE statement that will for observations that have TYPE equal to 'Hamburger' change the value of WEIGHT to have 5 more (assuming that units are the same) and also update the value of CALORIES to have 100 less calories (assuming that values are already in calories).
Then an answer might look like:
proc sql;
update FOOD
set weight=weight+5
, calories=calories-100
where type='Hamburger'
;
quit;
this is the error which i'm getting ,
you gave me the code i used
ERROR 73-322: Expecting an =.
ERROR 76-322: Syntax error, statement will be ignored.
64 , calories=calories-100
65 where type='Hamburger';
66 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
The code works for me. You didn't include enough of your SAS log for us to see what error you might have made.
data food;
length type $20 weight calories 8;
input type weight calories ;
cards;
Hamburger 20 500
Hamburger 24 600
Chips 5 1000
;
proc print data=food;
title 'BEFORE';
run;
proc sql;
update FOOD
set weight=weight+5
, calories=calories-100
where type='Hamburger'
;
quit;
proc print data=food;
title 'AFTER';
run;
BEFORE Obs type weight calories 1 Hamburger 20 500 2 Hamburger 24 600 3 Chips 5 1000 AFTER Obs type weight calories 1 Hamburger 25 400 2 Hamburger 29 500 3 Chips 5 1000
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.