Hi! I am stuck with the following: trying to calculate mean population for each state in 1910-2010 using sashelp.us_data. I also want to keep the following variables displayed: statename, avg_population and population_xxxx.
data usa;
set sashelp.us_data;
avg_population=mean(of population_1910-population_2010);
keep statename avg_population population_1910-population_2010;
run;
avg_population creates new variables such as population_1911, 1912 etc.
Anyone can help?
Thanks a lot!
It worked well but to simplify I did (based on your suggestion):
data usa;
set sashelp.us_data;
avg_population=mean(of POPULATION: );
keep avg_population statename population_1910-population_2010;
run;
Thanks a lot!
Please post sample data - few observations and relevant variables - of sashelp.us_data,
as it is not available on SAS UE.
Thanks! Posting sample data:
This might work, I also don't have US_DATA in UE.
data usa(keep=statename population: avg_population);
set sashelp.us_data;
avg_population = mean(of POPULATION:);
run;
-unison
edit to simplify.
It worked well but to simplify I did (based on your suggestion):
data usa;
set sashelp.us_data;
avg_population=mean(of POPULATION: );
keep avg_population statename population_1910-population_2010;
run;
Thanks a lot!
Please do not post pictures of data, as that would force us to waste time typing data off the screen item by item.
Post data in a data step with datalines like
data have;
input string $ date :yymmdd10. number;
format date yymmddd10.;
datalines;
A 2019-11-02 1
B 2019-11-03 2
;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.