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

Hi All,

 

I apologize if this has been asked before, this question is tricky to formulate, let alone find an answer in the forum. 

 

I have a table like this:

   

    data have;
    input theta1 theta3 sigma11 sigma13;
    datalines;
        . . . .
        0.22 . . .
        . . . .
        . 0.29 . .
        . . . .
        . . 0.02 -0.02
        . . . .
    ;
    run;

 

And I need to get a table like this: all values in one row:

 

    data want;
    input theta1 theta3 sigma11 sigma13 ;
    datalines;
        0.22 0.29 0.02 -0.02
    ;
    run;

 

I am curious if this can be done in few steps. I would appreciate any help!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @Dinurik  , @Reeza 's approach is neat. Hovvever,You need to create a junk BY variable in an intermediate step.


    data have;
    input theta1 theta3 sigma11 sigma13;
    datalines;
        . . . .
        0.22 . . .
        . . . .
        . 0.29 . .
        . . . .
        . . 0.02 -0.02
        . . . .
    ;
    run;

	data _have;
	 set have;
	 retain t 99999;
	 run;

data want;
 update _have(obs=0) _have;
 by t;
 drop t;
run; 

 

View solution in original post

5 REPLIES 5
Reeza
Super User
data want;
update have(obs=0) have;
run;

Usually you'd want a BY statement as well.

 


@Dinurik wrote:

Hi All,

 

I apologize if this has been asked before, this question is tricky to formulate, let alone find an answer in the forum. 

 

I have a table like this:

   

    data have;
    input theta1 theta3 sigma11 sigma13;
    datalines;
        . . . .
        0.22 . . .
        . . . .
        . 0.29 . .
        . . . .
        . . 0.02 -0.02
        . . . .
    ;
    run;

 

And I need to get a table like this: all values in one row:

 

    data want;
    input theta1 theta3 sigma11 sigma13 ;
    datalines;
        0.22 0.29 0.02 -0.02
    ;
    run;

 

I am curious if this can be done in few steps. I would appreciate any help!

 

 


 

Dinurik
Fluorite | Level 6

Hi Reeza,

Thanks! SAS returned this error message:


ERROR: UPDATE statement needs a BY statement.

ballardw
Super User

@Dinurik wrote:

Hi All,

 

I apologize if this has been asked before, this question is tricky to formulate, let alone find an answer in the forum. 

 

I have a table like this:

   

    data have;
    input theta1 theta3 sigma11 sigma13;
    datalines;
        . . . .
        0.22 . . .
        . . . .
        . 0.29 . .
        . . . .
        . . 0.02 -0.02
        . . . .
    ;
    run;

 

And I need to get a table like this: all values in one row:

 

    data want;
    input theta1 theta3 sigma11 sigma13 ;
    datalines;
        0.22 0.29 0.02 -0.02
    ;
    run;

 

I am curious if this can be done in few steps. I would appreciate any help!

 

 


This works for your specific example:

proc summary data=have ;
   var  theta1 theta3 sigma11 sigma13;
   output out=want (drop=_:) max=;
run;

However if you have any of the variables with more than one non-missing values then likely it won't yield what you want, and will only work for numeric values.

If you have data with more than one value for any of your variables then you need to provide an example what the output for that should look like.

novinosrin
Tourmaline | Level 20

Hi @Dinurik  , @Reeza 's approach is neat. Hovvever,You need to create a junk BY variable in an intermediate step.


    data have;
    input theta1 theta3 sigma11 sigma13;
    datalines;
        . . . .
        0.22 . . .
        . . . .
        . 0.29 . .
        . . . .
        . . 0.02 -0.02
        . . . .
    ;
    run;

	data _have;
	 set have;
	 retain t 99999;
	 run;

data want;
 update _have(obs=0) _have;
 by t;
 drop t;
run; 

 

Dinurik
Fluorite | Level 6

Hi @novinosrin ,

Thank you!

I created a junk id variable through id=_n_, and it didn't occur to me that id is not supposed to change for the update statement to work. Thank you so much for the explanations!

 

 

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 1063 views
  • 2 likes
  • 4 in conversation