DATA Step, Macro, Functions and more

Merging Issue

Reply
Occasional Contributor
Posts: 6

Merging Issue

Hello guys, for an assignment, I have to merge 2 sas datasets into a single temporary data set, as specified below:

QUESTION:
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:

 

EDITOR:
%let path=C:\445_695\Course_Data;
libname Assign2 "&path";

data Pur_Price;
    set Purchase Inventory  ;
run;

 

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:
      Engine:        V9
      Physical Name: C:\445_695\Course_Data
75
76   data Pur_Price;
77       set Purchase Inventory  ;
ERROR: File WORK.PURCHASE.DATA does not exist.
ERROR: File WORK.INVENTORY.DATA does not exist.
78   run;

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 ?

 

Thanks

Super User
Posts: 17,824

Re: Merging Issue

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;

 

 

Super User
Posts: 17,824

Re: Merging Issue


gf1996 wrote:

Hello guys

 

FYI - a large portion of participants on here are not guys. 

Respected Advisor
Posts: 4,646

Re: Merging Issue

You must prefix the dataset name with the library name

 

set Assign2.Purchase Assign2.Inventory;

 

WORK is the default library when no prefix is specified.

PG
Ask a Question
Discussion stats
  • 3 replies
  • 235 views
  • 3 likes
  • 3 in conversation