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!!
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.