BookmarkSubscribeRSS Feed
gf1996
Calcite | Level 5

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

3 REPLIES 3
Reeza
Super User

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;

 

 

Reeza
Super User

@gf1996 wrote:

Hello guys

 

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

PGStats
Opal | Level 21

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 1601 views
  • 3 likes
  • 3 in conversation