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;
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;
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.
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...
Hint: I don't think you need to do any coding to answer these questions.
@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.
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.