DATA Step, Macro, Functions and more

sas base and proc sql code for following question plz help

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

sas base and proc sql code for following question plz help

[ Edited ]

data have;

infile datalines missover dsd;

input name $ country $ salary;

datalines;

ganesh,, 40000

ganesh,india,         

;

run;

 

output data set should be like as under 

 

name country salary

ganesh india 40000

 

 

thanks in advance 


Accepted Solutions
Solution
4 weeks ago
Respected Advisor
Posts: 4,932

Re: sas base and proc sql code for following question plz help

Posted in reply to ganeshmule

To do this with SQL is not efficient:

 


proc sql;
select * 
from 
    (select unique name from have) 
    natural left join
    (select name, country from have where country is not missing)
    natural left join
    (select name, salary from have where salary is not missing);
quit;
PG

View solution in original post


All Replies
Super User
Posts: 19,861

Re: sas base and proc sql code for following question plz help

Posted in reply to ganeshmule

UPDATE statement is what you want/need.

Respected Advisor
Posts: 4,932

Re: sas base and proc sql code for following question plz help

Posted in reply to ganeshmule

Use the self-update trick where every non-missing variable overwrites the previous value within a by group.

 

data have;
infile datalines missover dsd;
input name $ country $ salary;
datalines;
ganesh,, 40000
ganesh,india,  
Smith,USA,
Smith,,100000 
;

proc sort data=have; by name; run;

data want;
update have(obs=0) have;
by name;
run;

proc print; run;
PG
Solution
4 weeks ago
Respected Advisor
Posts: 4,932

Re: sas base and proc sql code for following question plz help

Posted in reply to ganeshmule

To do this with SQL is not efficient:

 


proc sql;
select * 
from 
    (select unique name from have) 
    natural left join
    (select name, country from have where country is not missing)
    natural left join
    (select name, salary from have where salary is not missing);
quit;
PG
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 92 views
  • 0 likes
  • 3 in conversation