Help using Base SAS procedures

SET

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

SET


I have 3 datasets and each having 4 variables .......and setting them together..

The variables are not in order in each. they are jubbled and I am setting them together without formatting

these variables are also of not equal lengths and formats

After setting the three of them in the final resultant dataset follow the first dataset(in terms of length of variables, formats) etc etc

Also since for example the second variable in dataset2 is A will it go back to 1st oposition automatically after setting?????and so on??

dataset1

A  B  C  D

dataset2

B A C  D

dataset3

D  A B  C

data want;

set dataset1 dataset2 dataset3;

run;

Thanks


Accepted Solutions
Solution
‎06-11-2013 12:23 PM
Super User
Super User
Posts: 7,074

Re: SET

Posted in reply to robertrao

SAS will set the order and other attributes as soon as it can.

So the first reference to a variable will set its order.

The first reference that causes SAS to assume a type and length will set those.

The first referenced dataset with an attached format or label will set the label, but the last actual format or label assignment by code will override what it might decide from reading source datasets.

In your example the order will be A B C D because of DATASET1. The type and length will also match that in DATASET1.  SAS will move the values read from the other datasets around to put them in the right place.

View solution in original post


All Replies
Super Contributor
Posts: 334

Re: SET

Posted in reply to robertrao

Not exactly clear on your issue.

In simplistic terms, SAS sets the under based on the order of seeing the variables. So the first dataset read will set the order of the variables. If you declare the variables in a length statement you can control the order and set the maximum length you need across the three datasets.

If this doesnt help you might need to provide for information or a clearer question so the community can follow up.

EJ

Super Contributor
Posts: 1,041

Re: SET

So even the second dataset has B A C D order its gona become ABCD and gets apended?????

Regards

Super Contributor
Posts: 334

Re: SET

Posted in reply to robertrao

Unlike sql, SAS data step appends based on the variable names in the dataset and not the ordering of the variables in the sources.

EJ

Solution
‎06-11-2013 12:23 PM
Super User
Super User
Posts: 7,074

Re: SET

Posted in reply to robertrao

SAS will set the order and other attributes as soon as it can.

So the first reference to a variable will set its order.

The first reference that causes SAS to assume a type and length will set those.

The first referenced dataset with an attached format or label will set the label, but the last actual format or label assignment by code will override what it might decide from reading source datasets.

In your example the order will be A B C D because of DATASET1. The type and length will also match that in DATASET1.  SAS will move the values read from the other datasets around to put them in the right place.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 204 views
  • 5 likes
  • 3 in conversation