BookmarkSubscribeRSS Feed
user1942
Fluorite | Level 6

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:

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;
insert into problem3
set rtlcost=rtlcost*1.2
where ProdType<>='Software';
update problem3
set rtlcost=rtlcost*0.8
where ProdType='Workstation' or 'Laptop' or 'Phone';
select *
from problem3;
quit;
 
Here is the log that says what the error is (everything else was fine):
56   set rtlcost=rtlcost*1.2
57   where ProdType<>='Software';
     -----
     22
     76
ERROR 22-322: Syntax error, expecting one of the following: ;, !!, *, **, +, ',', -, /, SET, ||.
ERROR 76-322: Syntax error, statement will be ignored.
 
2 REPLIES 2
Shmuel
Garnet | Level 18

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. 

Krueger
Pyrite | Level 9

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;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 279 views
  • 0 likes
  • 3 in conversation