BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Magdalena56
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Magdalena56
Fluorite | Level 6

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!

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

Please post sample data - few observations and relevant variables - of sashelp.us_data,

as it is not available on SAS UE.

Magdalena56
Fluorite | Level 6

Thanks! Posting sample data:

 

sample data us.JPG

unison
Lapis Lazuli | Level 10

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.

-unison
Magdalena56
Fluorite | Level 6

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!

Kurt_Bremser
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 871 views
  • 3 likes
  • 4 in conversation