10-27-2016 05:15 PM
Hello guys, for an assignment, I have to merge 2 sas datasets into a single temporary data set, as specified below:
Merge the Purchase and Inventory data sets to create a new, temporary SAS data set (named Pur_Price) where
the Price value found in the Inventory data set is added to each observation in the Purchase data set,
based on the Model number (Model). There are some models in the Inventory data set that were not purchased
(and, therefore, are not in the Purchase data set). Do not include these models in your new data set.
Based on the variable Quantity in the Purchase data set, obtain a total cost (TotalCost) equal to Quantity x Price
in this data set as well. */
Here is the code I wrote, creating a the libname to direct to my sas data sets:
libname Assign2 "&path";
set Purchase Inventory ;
However, once I submit the code, I receive the following message:
73 %let path=C:\445_695\Course_Data;
74 libname Assign2 "&path";
NOTE: Libref ASSIGN2 refers to the same physical library as TMP2.
NOTE: Libref ASSIGN2 was successfully assigned as follows:
Physical Name: C:\445_695\Course_Data
76 data Pur_Price;
77 set Purchase Inventory ;
ERROR: File WORK.PURCHASE.DATA does not exist.
ERROR: File WORK.INVENTORY.DATA does not exist.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.PUR_PRICE may be incomplete. When this step was stopped there were
0 observations and 0 variables.
WARNING: Data set WORK.PUR_PRICE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Could anyone help me out with why the datasets would be assigned to the work library and not my created library Assign2 ?
10-27-2016 10:27 PM
You need to direct them to your library. However, you're not 'merging' datasets here, you're appending the datasets.
%let path=C:\445_695\Course_Data; libname Assign2 "&path"; data Pur_Price; set assign2.Purchase (in=pur) assign2.Inventory (in=inv) ; run;
This page in the documentation covers many of the different ways of combining SAS datasets.
I think you're looking for a one to one merge instead, so something like the following:
data Pur_Price; merge assign2.Purchase (in=pur) assign2.Inventory (in=inv) ; by Model; if pur=1; run;