BookmarkSubscribeRSS Feed
Amy0223
Quartz | Level 8

Hi, I'm not sure about the question below. Any help is much appreciated!

 

What if anything, is wrong with the following programs?

a. data new; update one two three; by id;

b. data new; update transact master; by id;

9 REPLIES 9
Reeza
Super User
What are your answers and logic?
Amy0223
Quartz | Level 8

Below are my answers, please correct me if I'm wrong. Thank you!

*4a Answer: using the datasets I made up, the log window shows ERROR 411-185: The UPDATE statement requires two data sets, too many data sets have been specified.;

data one;
input ID SALARY;
datalines;
011 376
026 .
028 374
;
proc print;
title 'one';
run;

data two;
input ID SALARY;
datalines;
011 322
026 123
028 374
;
proc print;
title 'two';
run;

data three;
input ID SALARY;
datalines;
011 302
026 234
028 311
;
proc print;
title 'three';
run;

data new; 
update one two three; 
by id;
proc print;
title 'update one two three';
run;

*4b Answer: using the dataset I created, the log window shows no errors. Therefore, there is nothing wrong;

data transact;
input ID SALARY;
datalines;
011 376
026 .
028 374
;
proc print;
title 'Transact';
run;

data master;
input ID SALARY;
datalines;
011 245
026 269
028 374
;
proc print;
title 'Master';
run;

data new;
update transact master;
by id;
proc print;
title 'Update Transact with Master';
run;
Tom
Super User Tom
Super User

The second statement is wrong.  Either they have the datasets listed in the wrong order, the transaction dataset should be listed last.  Or they have named their datasets backwards.  Either way the program is wrong.

Your example works because both your transaction dataset and your source dataset have only one observation per group.  If you have multiple transaction for one or more by group and gave SAS the datasets in the wrong order it would complain when it found if there were multiples observations for the same by group in the source dataset.

SASKiwi
PROC Star

If you review the documentation for the UPDATE statement then the answers should be more obvious: https://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=p18w3br45er2qun1r8sfmm4grjyr.htm&doc...

Amy0223
Quartz | Level 8
Thank you for the link!
SASKiwi
PROC Star

Hint: I don't think you need to do any coding to answer these questions.

Reeza
Super User
Your answers and tests look correct to me 🙂
SASKiwi
PROC Star

@Amy0223  - Are coded answers expected for these questions? If not I think it would be perfectly OK to answer question B: The MASTER and TRANSACT datasets are listed in the wrong order.

Amy0223
Quartz | Level 8
I didn't realize they are in wrong order. Thank you 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 754 views
  • 6 likes
  • 4 in conversation