Hello, I have a single row of data in my data data with probably 20 variables. I'm interested in converting this to separate observations but without using proc transpose. I know that I can do data foo; set my_data; to read in my data set. Then I thought I might be able to do something like input my_var @@; in order to covert the variables into observations but it looks like if I use the input statement, I also need to follow it with the datalines and then the data hardcoded in.
Could someone steer me in the right direction?
Not sure if this is what you want, but I think it meets your description:
data have;
input var1-var10 col1-col10;
cards;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
;
data want (keep=variable);
set have;
array vars _all_;
do over vars;
variable=vars;
output;
end;
run;
Not sure if this is what you want, but I think it meets your description:
data have;
input var1-var10 col1-col10;
cards;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
;
data want (keep=variable);
set have;
array vars _all_;
do over vars;
variable=vars;
output;
end;
run;
Thanks for your help. I've got one other question.
I have a number of observations sorted by a var1 and I want to find the median of var1 of these observations in a data step. I know I can do n=_n_; which will add the variable with the observation number. But then how can I get the middle observation (if the n is odd) or average the two middle observations (if the n is even). I'd like to assume in my code that I don't know the number of observations that exists in my data set.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.