BookmarkSubscribeRSS Feed
Tobiasp94
Calcite | Level 5

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
andreas_lds
Jade | Level 19

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

 

 

 

Patrick
Opal | Level 21

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1249 views
  • 0 likes
  • 4 in conversation