Here's one that Excel can do, so I'll use Excel if no fairly easy SAS way is possible.
Note following portion of data set:
Combo | Var_1 | Var_2 |
20101_21603 | 0. | -1.94930 |
20101_21603 | 0. | -1.80663 |
20101_21603 | 0. | -1.66396 |
20101_21603 | 0. | -1.52129 |
21603_20101 | -0.80794 | 0. |
21603_20101 | -0.66527 | 0. |
21603_20101 | -0.52260 | 0. |
21603_20101 | -0.37993 | 0. |
Focus only on the Var_1 and Var_2 columns..., at least for the time being.
I need to "swap" the contents of the bottom four rows of cells.
Does SAS have a way to do this -- without your having to write tons of code?
Thanks much.
Nicholas Kormanik
There is no data step swap function (I've occasionally wished for it) but you can temporarily create another column say temp, then use code such as
If (condition to select rows to swap)
then do ;
temp = Var_1 ;
Var_1 = Var2 ;
Var_2 = temp ;
end ;
drop temp ;
You can also do it in sql, without creating a temp column but it is a lot more verbose.
Richard
Unclear where you write the line for tons , but here goes (assuming that you need to store column with values <> 0 in one column):
proc sql;
update mytable
set var_2 = var_1
where var_1 <> 0 and var_2 = 0
;
quit;
Comparing to Excel is puzzling me. Excel is great when doing minor ad-hoc stuff, SAS is suited for developing programs that can be used multiple times, in batch etc.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: