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 😉
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.