Hello experts, I'm having trouble with this exercise. I am supposed to add a new row to my data table, which worked. Then, I need to have a 20% increase on software products, and 20% discount on all other products. My code keeps having errors and I'm not sure how to fix this. Please help!
Here is my code:
The where satement is used to select rows from a dataset.
Use CASE statement to define when to do the calculation.
The code should look like:
proc sql;
.....
case (ProdType<>='Software') then set rtlcost*1.2 as rtlcost;
Check for the exact systax.
ProdType is mispelled and actually "PodType" but below is a way of doing this with PROC SQL;
Edit: You have multiple other issues with your input step as well. Either this was due to your copy/paste and/or not inserting the code into the code brackets or due to your original input. You will need to fix that as well.
data problem3;
input ProdNum ProdName$ 6-27 ManuNum PodType$33-43 RtlCost dollar8.0;
format RtlCost dollar8.0;
put (_all_) (=);
cards;
5009 Dream Machine 500 Workstation $3,200
4506 Business Machine 450 Workstation $3,345
2101 Travel Laptop 400 Laptop $2,760
2212 Analog Cell Phone 230 Phone $35
4509 Digital Cell Phone 245 Phone $175
5003 Office Phone 560 Phone $145
1110 Spreadsheet Software 134 Software $300
1200 Database Software 113 Software $799
3409 Statistical Software 243 Software $1,899
2102 Wordprocessor Software 245 Software $345
2200 Graphics Software 246 Software $599
;
proc print data=problem3;
run;
proc sql;
insert into problem3
values(3480, 'Desktop Computer', 780, 'Workstation', 1799);
select *
from problem3;
quit;
proc sql;
CREATE TABLE Want AS
SELECT *
,CASE WHEN PodType IN ('Workstation', 'Laptop', 'Phone') THEN rtlcost*0.8
ELSE rtlcost*1.2
END AS newrtlcost
FROM Problem3;
QUIT;
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.