BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8


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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
esjackso
Quartz | Level 8

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

robertrao
Quartz | Level 8

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

Regards

esjackso
Quartz | Level 8

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

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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