×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Rearrange pre-existing workfile

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

RE: Rearrange pre-existing workfile

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;

RE: Rearrange pre-existing workfile

(OP)
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

RE: Rearrange pre-existing workfile

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?

RE: Rearrange pre-existing workfile

(OP)
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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close