BookmarkSubscribeRSS Feed
NCSU_2016
Fluorite | Level 6

Hi All, 

 

I am confused about how to arrange my data to run a probit model. 

 

I have data on 484 farms over 132 months for four variables. I am aware the data needs to be in stacked form such that farms have a column, months have a column, and variables are in their respective columns, rather than a column for each month as is currently the case. 

 

Currently, I have each variable in its own matrix/spreadsheet. 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, costs, and exit decision. 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!!

2 REPLIES 2
stat_sas
Ammonite | Level 13

May be this is what you are looking for

 

data have;
input Farm $ Month_1 $ Month_2 $ Month_3 $;
datalines;
Farm_1 Q_1_1 Q_1_2 Q_1_3
Farm_2 Q_2_1 Q_2_2 Q_2_3
;

 

data want(keep=farm months values);
set have;
array m(*) m:;
do i=1 to dim(m);
Months=vname(m(i));
Values=m(i);
output;
end;
run;

TomKari
Onyx | Level 15

Using PROC TRANSPOSE will get you most of the way there:

 

data Var1;

input Farm $ Month_1 Month_2 Month_3;

cards;

Farm1 1 2 3

Farm2 4 5 6

Farm3 7 8 9

run;

proc sort data=Var1;

by Farm;

proc transpose data=Var1 out=TransposedVar1(rename=(col1=Var1));

by Farm;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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