data have;
input state $ income;
datalines;
delhi 1000
delhi 3000
chandigarh 4000
chandigarh 3000
patna 300
delhi 400
;
run;
data want;
input state $ income;
datalines;
delhi 4400
chandigarh 7000
;
run;
As written, the length of the state variable in your have and want datasets will default to 8 - too small to hold all the values. Try this:
data have;
length state $ 10;
input state $ income;
datalines;
delhi 1000
delhi 3000
chandigarh 4000
chandigarh 3000
patna 300
delhi 400
;
run;
data want;
length state $ 10;
input state $ income;
datalines;
chandigarh 7000
delhi 4400
;
run;
proc sql;
/*create table want as */
select state, sum(income)
from have
where lowcase(state) in ('delhi','chandigarh')
group by state
;
quit;
May the SAS be with you 😉
Use a where= dataset option:
proc summary data=have (where=(state in ("...","...")));
by state;
var income;
run;
As written, the length of the state variable in your have and want datasets will default to 8 - too small to hold all the values. Try this:
data have;
length state $ 10;
input state $ income;
datalines;
delhi 1000
delhi 3000
chandigarh 4000
chandigarh 3000
patna 300
delhi 400
;
run;
data want;
length state $ 10;
input state $ income;
datalines;
chandigarh 7000
delhi 4400
;
run;
proc sql;
/*create table want as */
select state, sum(income)
from have
where lowcase(state) in ('delhi','chandigarh')
group by state
;
quit;
May the SAS be with you 😉
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.