I have uploaded a dataset with multiple variables into SAS Studio. These variables varies across time.
For instance i need to create one variable population instead of 7 variables:
Population <- Population_2010 + Population_2011 + ....
Hope someone can help.
It is recommend to avoid data in variable-names. Having one variable with the year and another with the value allows easier usage of the data. If you have to create a dataset with those year-variables you need to post a data-step with datalines statement showing the data you have. This post explains how to transform data into a data-step.
Note I am assuming your data here:
data have;
country="UK";
population_2010=10;
population_2011=20;
output;
country="US";
population_2010=15;
population_2011=25;
output;
run;
proc transpose data=have out=want;
by country;
var population_:;
run;
Here a data step option to also populate a Year variable.
data have;
country="UK";
population_2010=10;
population_2011=20;
output;
country="US";
population_2010=15;
population_2011=25;
output;
run;
data want(drop=_: population_:);
set have;
length year $4 pop_count 8;
array _pop {*} population_:;
do _i=1 to dim(_pop);
year=scan(vname(_pop[_i]),2,'_');
pop_count=_pop[_i];
output;
end;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.