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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

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;

eggman2001
Calcite | Level 5

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1941 views
  • 0 likes
  • 2 in conversation