BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Praveenit0808
Calcite | Level 5
Can anyone help how to move values from one observation to another?

aa 11 101
bb 14 201
cc 13 303
dd 12 404
dd 17 505
;
run;
O/P like this
aa 12 101
aa 17 505
bb 14 201
cc 11 303
dd 13 404
;
run;

Can it be possible?
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Is it possible? Almost anything is possible.

Do I know what you're trying to do? No!

Can one write code that produces what you want? Of course!

 

data have;
  input x $ y z;
  cards;
aa 11 101
bb 14 201
cc 13 303
dd 12 404
dd 17 505
;

data x(keep=x) y(keep=y y1) z(keep=z z1);
  set have;
  select (_n_);
    when (1) do;
      y1=4;
      z1=1;
    end;
    when (2) do;
      y1=3;
      z1=3;
    end;
    when (3) do;
      y1=5;
      z1=4;
    end;
    when (4) do;
      x='aa';
      y1=1;
      z1=5;
    end;
    otherwise do;
      y1=2;
      z1=2;
    end;
  end;
run;

proc sort data=x;
  by x;
run;

proc sort data=y;
  by y1;
run;

proc sort data=z;
  by z1;
run;

data want (keep=x y z);
  set x;
  set y;
  set z;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

7 REPLIES 7
ChrisBrooks
Ammonite | Level 13

Hi Praveen

 

I think you'll have to give us some more detail about the logic you want to use in order to get an answer to this

Praveenit0808
Calcite | Level 5
Thank you so much for helping me. However what exactly I need is. Here is
the problem:

Input name $ status ;
Cards;
Aa active
Aa active
Aa active
Aa active
Aa active
Bb deactivated
Bb deactivated
Bb deactivated
Dd deactivated
Dd deactivated
Ee active
Ee active
Ee active
Cc active
Cc active
;
Run;

O/p should be like this


Aa active
Aa active
Aa active
Aa active
Aa active
Cc active
Cc active
Cc active
Ee active
Ee active
Ee active
Ee active
Ee active
Cc active
Cc active

How do we do that?


##- Please type your reply above this line. Simple formatting, no
attachments. -##
PeterClemmensen
Tourmaline | Level 20

I dont see the logic here, please provide more information.

art297
Opal | Level 21

Is it possible? Almost anything is possible.

Do I know what you're trying to do? No!

Can one write code that produces what you want? Of course!

 

data have;
  input x $ y z;
  cards;
aa 11 101
bb 14 201
cc 13 303
dd 12 404
dd 17 505
;

data x(keep=x) y(keep=y y1) z(keep=z z1);
  set have;
  select (_n_);
    when (1) do;
      y1=4;
      z1=1;
    end;
    when (2) do;
      y1=3;
      z1=3;
    end;
    when (3) do;
      y1=5;
      z1=4;
    end;
    when (4) do;
      x='aa';
      y1=1;
      z1=5;
    end;
    otherwise do;
      y1=2;
      z1=2;
    end;
  end;
run;

proc sort data=x;
  by x;
run;

proc sort data=y;
  by y1;
run;

proc sort data=z;
  by z1;
run;

data want (keep=x y z);
  set x;
  set y;
  set z;
run;

Art, CEO, AnalystFinder.com

 

novinosrin
Tourmaline | Level 20

Is it possible? Almost anything is possible.

Do I know what you're trying to do? No!

Can one write code that produces what you want? Of course!

 

@art297  I love your sense of humor. I hope you are having a great weekend!

mkeintz
PROC Star

This is an excellent response, and should be marked as the solution.

 

 

it's so good, we don't need to know what the problem is. ... and we don't.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Praveenit0808
Calcite | Level 5
Yes thank so you much for your prompt response ....I'll definitely implement those steps in my program ...

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1695 views
  • 5 likes
  • 6 in conversation