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

Hi All, 

 

I am confused about how to arrange my data to run a probit model. I am aware the model needs to be run in another package other than IML (namely QLIM), but I thought it would be easiest to arrange the data using IML. 

 

I have data on 484 farms over 132 months for four variables. Currently, I have each variable in its own matrix as follows:

 

Here is the Quantity Matrix:

 

               Month_1    Month_2 .... Month_j

Farm_1    Q_1_1       Q_1_2            Q_1_j

Farm_2    Q_2_1       Q_2_2            Q_2_j

.                  .

.

Farm_i    Q_i_1       Q_i_2                Q_i_j          

 

 

 

I have matrices of equal dimensions for prices, variable costs, and total costs. Column j represents the j'th month and row i represents the i'th farm in each matrix. 

 

If anyone can give me some guidance about how to arrange this data, I would greatly appreciate it. Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Use the COLVEC function to create a single vector from each matrix.  Then save the data to a SAS data set, along with indicator variables for the MONTH and FARM variables.  This is called transforming the data from "wide to long" form.  You might like to read the article "Plotting multiple time series in SAS/IML."

 

You can use the ROW and COL functions to easily create the indicator variables, as follows:

proc iml;
/* 4 months (columns) and 3 farms (rows) */
Q = {1  2  3  4,
     5  6  7  8,
     9 10 11 12};
Qvec = colvec(Q);
Farm = colvec(row(Q));
Month = colvec(col(Q));
print Farm Month QVec;

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

Use the COLVEC function to create a single vector from each matrix.  Then save the data to a SAS data set, along with indicator variables for the MONTH and FARM variables.  This is called transforming the data from "wide to long" form.  You might like to read the article "Plotting multiple time series in SAS/IML."

 

You can use the ROW and COL functions to easily create the indicator variables, as follows:

proc iml;
/* 4 months (columns) and 3 farms (rows) */
Q = {1  2  3  4,
     5  6  7  8,
     9 10 11 12};
Qvec = colvec(Q);
Farm = colvec(row(Q));
Month = colvec(col(Q));
print Farm Month QVec;
NCSU_2016
Fluorite | Level 6

Wow, thanks Rick. You are a wonderful help every time. I appreciate your expertise!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1116 views
  • 0 likes
  • 2 in conversation