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

Hello,

I have a dataset ("population") consisting of about 10 000 observations. This dataset contains a variable "CITY", ranged 1 to 79 and a variable "AGE", ranged 0 to 75. In an Excel file, I have a value for each possibilites of these two variables (i.e. 79*76 lines). This variable is in fact a corrected ponderation that I need to assign to the observations of the dataset "population".

I suppose I could a large number of "if then" commands like this:

if city=1 then do;

if age=0 then pond=1.2;

if age=1 then pond=0.9;

...

end;

if city=79 then do;

if age=75 then pond=1.3;

end;

But I guess it's not the more efficient way.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Off course there is. Assuming you imported your Excel sheet as a dataset called PONDERATION with columns AGE CITY and POND, the following query will join the two :

proc sql;

create table want as

select population.*, ponderation.pond

from population natural join ponderation;

quit;

PG

PG

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

Off course there is. Assuming you imported your Excel sheet as a dataset called PONDERATION with columns AGE CITY and POND, the following query will join the two :

proc sql;

create table want as

select population.*, ponderation.pond

from population natural join ponderation;

quit;

PG

PG
Demographer
Pyrite | Level 9

It works, thank you.

What means the "natural join" statement?

PGStats
Opal | Level 21

It means join on the columns with the same name. - PG

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