BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NinaWestern
Obsidian | Level 7

Hello everyone,

I would appreciate your input.

I need to add a variable from one data set to another one. They are both sorted by the key variable. I used a proc sql syntax posted here in another thread, but keep receiving error messages.

 

DDini- main data set

DD2- the second data set, from which I need only one variable, named ib14_new.

Here is my syntax:

 

proc sql;

create table DDm

as select work.DDini.*, work.DD2.ib14_new

from work.DDini left join work.DD2

on work.DDini.crn= work.DD2.crn;

quit;

 

The error message is attached.

Any help resolving this is very appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Because of the several ways that SAS uses a dot in constructing various items in syntax you can't have more than one . (other than macro variables) to  reference data set and variable names. So you need to create an alias that means the library.dataset combination.

 

proc sql;
   create table DDm
   as select A.*, B.ib14_new
   from work.DDini as A left join work.DD2 as B
   on A.crn= B.crn;
quit;

I explicitly use "as A" to set the alias but simple "work.DDini A" would work.

Of course the default library for data sets with a single level name means you can probably drop the "work." everywhere

 

BTW it is best on this forum to paste text such as LOG entries or code into a text box opened on the forum with the </> icon to preserve formatting.

Many won't open DOCX, or several other file formats from unknown users either by choice or organization policy.

View solution in original post

2 REPLIES 2
ballardw
Super User

Because of the several ways that SAS uses a dot in constructing various items in syntax you can't have more than one . (other than macro variables) to  reference data set and variable names. So you need to create an alias that means the library.dataset combination.

 

proc sql;
   create table DDm
   as select A.*, B.ib14_new
   from work.DDini as A left join work.DD2 as B
   on A.crn= B.crn;
quit;

I explicitly use "as A" to set the alias but simple "work.DDini A" would work.

Of course the default library for data sets with a single level name means you can probably drop the "work." everywhere

 

BTW it is best on this forum to paste text such as LOG entries or code into a text box opened on the forum with the </> icon to preserve formatting.

Many won't open DOCX, or several other file formats from unknown users either by choice or organization policy.

NinaWestern
Obsidian | Level 7
@ballardw, thank you! It did work!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 666 views
  • 0 likes
  • 2 in conversation