BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
pavank
Quartz | Level 8
Input values ;
Cards
12 33 56 77 99;
run
Q.) swap 33 and 77 values remaining keep same
Output
12 77 56 33 99
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

If that's not just an "academic" question then you will likely need to provide more information to get a suitable answer. 

Please also provide a fully working data step that creates the have data and show us the desired result so we understand if that's about switching values between variables on a single row or if it is about swapping rows.

 

Variable swap:

data have;
  infile datalines dlm=' ';
  input var1-var5;
  _v=var2;
  var2=var4;
  var4=_v;
  drop _v;
Cards;
12 33 56 77 99
;
run;

proc print data=have;
run;

 

Row swap:

data have;
  infile datalines dlm=' ';
  input var @@;
Cards;
12 33 56 77 99
;
run;

data want;
  do _i=1,4,3,2,5;
    set have point=_i;
    output;
  end;
  stop;
run;

proc print data=want;
run;

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

If that's not just an "academic" question then you will likely need to provide more information to get a suitable answer. 

Please also provide a fully working data step that creates the have data and show us the desired result so we understand if that's about switching values between variables on a single row or if it is about swapping rows.

 

Variable swap:

data have;
  infile datalines dlm=' ';
  input var1-var5;
  _v=var2;
  var2=var4;
  var4=_v;
  drop _v;
Cards;
12 33 56 77 99
;
run;

proc print data=have;
run;

 

Row swap:

data have;
  infile datalines dlm=' ';
  input var @@;
Cards;
12 33 56 77 99
;
run;

data want;
  do _i=1,4,3,2,5;
    set have point=_i;
    output;
  end;
  stop;
run;

proc print data=want;
run;
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
  • 1 reply
  • 814 views
  • 0 likes
  • 2 in conversation