BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
E_W
Calcite | Level 5 E_W
Calcite | Level 5

There was recently a change in methodology in how certain programs are categorized. What was before something like this:

 

County   State             Program   Category          Revenue   Cost    Profit

Drew      Arkansas      P23            Grass Seeds    $100          $80      $20

 

Has now been divided into two different categories that split the revenue, cost, and profit between the two at predetermined ratios. For P23, it would be 25% towards Wild Grass Seeds and 75% towards Grass/Legume Seeds.

 

County   State             Program   Category                            Revenue   Cost    Profit

Drew      Arkansas      P23            Wild Grass Seeds            $25          $20      $5

Drew      Arkansas      P23            Grass/Legume Seeds     $75          $60      $15

 

What would be the function or code needed to trawl through the existing dataset and replace all the existing P23's with the new Categories and figures while keeping other columns like County and State intact? Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Maybe like this.

 

data want;
   length category $ 40;
   set have;
   if program='P23' then do;
      _revenue =  revenue;
      _cost    =  cost;
      _profit  =  profit;  

      category =  'Wild Grass Seeds';
      revenue  =  _revenue*0.25;
      cost     =  _cost*0.25;
      profit   =  _profit*0.25;
      output;
      category =  'Grass/Legume Seeds';
      revenue  =  _revenue*0.75;
      cost     =  _cost*0.75;
      profit   =  _profit*0.75;
      output;
      end;
   else output;
   drop _:;
   run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
data want;
    length category $ 40;
    set have;
    if program='P23' then do;
        category='Wild Grass Seeds';
        revenue1=revenue*0.25;
        cost1=cost*0.25;
        profit1=profit*0.25;
        output;
        category='Grass/Legume Seeds';
        revenue1=revenue*0.75;
        cost1=cost*0.75;
        profit1=profit*0.75;
        output;
    end;
    else output;
run;
--
Paige Miller
E_W
Calcite | Level 5 E_W
Calcite | Level 5

Thank you, Paige. Is there a way to do this without creating new column names? There are other programs that have data in the same column and I would like to maintain that.

data_null__
Jade | Level 19

Maybe like this.

 

data want;
   length category $ 40;
   set have;
   if program='P23' then do;
      _revenue =  revenue;
      _cost    =  cost;
      _profit  =  profit;  

      category =  'Wild Grass Seeds';
      revenue  =  _revenue*0.25;
      cost     =  _cost*0.25;
      profit   =  _profit*0.25;
      output;
      category =  'Grass/Legume Seeds';
      revenue  =  _revenue*0.75;
      cost     =  _cost*0.75;
      profit   =  _profit*0.75;
      output;
      end;
   else output;
   drop _:;
   run;
PaigeMiller
Diamond | Level 26

@E_W wrote:

Thank you, Paige. Is there a way to do this without creating new column names? There are other programs that have data in the same column and I would like to maintain that.


After you create a data set with the new column names, you can move the values into the old column names and then delete the new column names.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 4 replies
  • 493 views
  • 0 likes
  • 3 in conversation