DATA Step, Macro, Functions and more

Assign value following many conditions

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 113
Accepted Solution

Assign value following many conditions

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


Accepted Solutions
Solution
‎07-20-2013 02:55 PM
Respected Advisor
Posts: 4,928

Re: Assign value following many conditions

Posted in reply to Demographer

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


All Replies
Solution
‎07-20-2013 02:55 PM
Respected Advisor
Posts: 4,928

Re: Assign value following many conditions

Posted in reply to Demographer

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
Frequent Contributor
Posts: 113

Re: Assign value following many conditions

It works, thank you.

What means the "natural join" statement?

Respected Advisor
Posts: 4,928

Re: Assign value following many conditions

Posted in reply to Demographer

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

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 218 views
  • 0 likes
  • 2 in conversation