DATA Step, Macro, Functions and more

Merge

Reply
Occasional Contributor
Posts: 7

Merge

data Merge1;
merge Airbag.ctl Alignmt.ctl;
by Report_Number;
run;

Am trying to merge the datasets Airbag and Alignmt but I received the following error messages

ERROR: Libref AIRBAG is not assigned

ERROR: Libref ALIGNMT is not assigned

Moses

 

 

PROC Star
Posts: 288

Re: Merge

You are specifying your table names as libraries and your library as the table name.

 

I assume you want:

 

data Merge1;
 merge ctl.Airbag ctl.Alignmt;
 by Report_Number;
run;

 

 

Occasional Contributor
Posts: 7

Re: Merge

No this doesnt work. It now says "Libref CTL is not assigned

Super User
Super User
Posts: 7,392

Re: Merge

The log error tells you everything you need to know, you have no libraries setup for those two references.  A libname is a container for other files such as datasets, and you assign these by:

libname <reference> "<network path to files>";

e.g. 

libname mine "c;\myfolder";
This creates a library reference mine, pointing to that path.  And you can use this to reference datasets witihn that folder by:

data want;
  set <reference>.<dataset>;
run;

Occasional Contributor
Posts: 7

Re: Merge

Thank you. Eventually, this is what I did after watching some videos from Techsupport. I created a libref and that solved the problem, and I was able to merge. Thank you. But another problem emerged. The ID column that I am merging by, has multiple data in some of the tables. So when I sort the data SAS tells me that the tables are not well sorted and it stops after reading less that half of the rows.

Occasional Contributor
Posts: 7

Re: Merge

Please attached is my full screen. I am very new using SAS,trying to learn by myself and this is my very first task I am trying to perform, so I need help and direction,

Thanaks

Super User
Super User
Posts: 7,392

Re: Merge

Sorry, opening attachment files is a security risk.  I would recommend you follow the SAS video training:

http://support.sas.com/training/tutorial/

As this will explain things - assigning libraries is pretty much learning step 1.

Occasional Contributor
Posts: 7

Re: Merge

ok thank you

Occasional Contributor
Posts: 7

Re: Merge

Thank you. Watching the tutorial helped. I created the libref and it worked. But only few rows were merged because SAS could not sort the data correctly. The ID column that I am merging by, has repeated names in most of the rows. So when I sort the data SAS gives an error message that the tables are not well sorted.

Trusted Advisor
Posts: 1,369

Re: Merge

I understand that Airbag and Alignment are two sas datasets.

Are they in a subdirectory named ctl ?

If yes - add a line ahead of your code:

libname ctl "...path to the subdirectory ...";

then use datasetst as: ctl.Airbag, ctl.Alignment.

Occasional Contributor
Posts: 7

Re: Merge

I performed the merge after watching some tutorial videos on creating libref. I created the libref and it worked. But only few rows were merged because SAS could not sort the data correctly. The ID column that I am merging by, has repeated names in most of the rows. So when I sort the data SAS gives an error message that the tables are not well sorted.

PROC Star
Posts: 7,360

Re: Merge

Looks like you're using SAS UE. Try the following (although you may have to first sort all of those files by Report_Number) and I may have misspelled some of your file names:

 

libname ctl "/folders/myfolders";

data merge1;
  merge ctl.airbag ctl.alignment ctl.driver ctl crashcha
          ctl.inserty ctl.speed ctl.weather;
  by Report_Number;
run;

Art, CEO, AnalystFinder.com

Ask a Question
Discussion stats
  • 11 replies
  • 287 views
  • 0 likes
  • 5 in conversation