Rearrange pre-existing workfile
Rearrange pre-existing workfile
(OP)
I have a program that creates many workfiles in this order:
1 2
3 4
...
9 10
How do I get them into this order:
1
2
.
.
.
9
10
I want to use a macro so I can update and merge multiple work files quickly.
It is the same as:
data a; input var1 @@;
datalines;
1 2
3 4
...
9 10
but without the datalines section, as the data is already in SAS as a work file
1 2
3 4
...
9 10
How do I get them into this order:
1
2
.
.
.
9
10
I want to use a macro so I can update and merge multiple work files quickly.
It is the same as:
data a; input var1 @@;
datalines;
1 2
3 4
...
9 10
but without the datalines section, as the data is already in SAS as a work file
RE: Rearrange pre-existing workfile
Maybe something along the lines of:
data a; input var1 var2;
datalines;
1 2
3 4
run;
data b (keep=var1);
set a;
run;
data c (keep=var2);
set a;
run;
data c;
set c;
rename var2=var1;
run;
data all;
set b c;
run;
proc sort data = all;
by var1;
run;
RE: Rearrange pre-existing workfile
The data in All before sorting:
1
3
2
4
Then it's sorted with proc sort
Thanks though, it may have put me in the right direction, maybe some transposing or something
RE: Rearrange pre-existing workfile
You gave an example:
data a; input var1 @@;
datalines;
1 2
3 4
...
9 10
Which would give:
var1 var2
1 2
3 4
And my code splits and rearranges these in sequential order?
What do you mean by work files exactly...
Do you mean SAS datasets in the work library that you want to merge together?
RE: Rearrange pre-existing workfile
Your last post gave me an idea whereby I manually create a new dataset with exact number values in "a":
var1 var2
1 2
3 4
with the same number of rows as the datasets (workfile) I'm working with.
I then pair var1 with a variable of interest from my workfile, do the same for var2 (both in separate new SAS datasets), rename var2 as var1, then use the set function in the dataset to vertically concatenate, and then sort by var1.
It works, without your last post, I never would have thought of using proc sort to make it work.
Thanks a bunch! A huge workload has just been cut out of my project(s)