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

Hi everyone,

I have a problem when I was developing an optimization model.

I have a data set in hand which has four columns: ID, frt_val, mid_val and bck_val, and I want to create another data set which is the parameters table for the optimization problem. The length of the parameters table can dynamically change based on number of &Vol. Suppose we set %let Vol = 8; how can I create a table which has &Vol + 1 columns (one for ID), such that the second column stores value of frt_val, the last column stores value of bck_val, and values from columns 3 to 7 are equivalent to mid_val?

Thank you a lot for your help!

YH Fung

As an example:

table 1:

ID        frt_val      mid_val      bck_val

101       100           99               109

102        -10          20                 -9

...          ...            ...                 ...

how can I create table 2 as following?

table 2:

ID       vol1     vol2   vol3    vol4     vol5      vol6    vol7    vol8 

101    100       99     99      99       99        99      99       109

102    -10        20     20      20       20        20      20       -9

...        ...       ...      ...       ...       ...        ...        ...       ...

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

Here's one way:

data want(keep=ID vol:);

   set have;

   array vol[&Vol];

   vol1 = frt_val;

   do j = 2 to &Vol-1;

      vol = mid_val;

   end;

   vol&Vol = bck_val;

run;

View solution in original post

3 REPLIES 3
RobPratt
SAS Super FREQ

Here's one way:

data want(keep=ID vol:);

   set have;

   array vol[&Vol];

   vol1 = frt_val;

   do j = 2 to &Vol-1;

      vol = mid_val;

   end;

   vol&Vol = bck_val;

run;

YH
Calcite | Level 5 YH
Calcite | Level 5

Hi RobPratt,

It works! Thank you so much for your help!

YH Fung

RobPratt
SAS Super FREQ

Glad to help.  Please mark this question Answered.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 789 views
  • 0 likes
  • 2 in conversation