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.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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