- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-22-2019 01:21 AM
(1433 views)
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.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;