Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rearrange pre-existing workfile

Status
Not open for further replies.

jackandrew

Technical User
Jan 8, 2011
4
US
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
 
Hi,

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;
 
well that worked, primarily because it was sorted at the end.
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
 
The proc sort at the end was put in case the numbering wasn't pre sorted.

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?
 
Yea they are SAS datasets I create with a different code, they all have the number of columns and rows but also different values.

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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top