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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 710 views
  • 0 likes
  • 2 in conversation