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

Hi fellow experts,

 

I have a dataset containing all the historic (hist_data) informations about a specific kind of data (e.g. mean, min, max, etc.). It all stands in one row and it's updated each month once the latest file is uploaded.

 

However, for quality control of my latest data (ex: new_data), I would like to use this row of observations (mean, min, max, etc.) to validate datas in another set.

 

I was thinking of creating a new column into new_data with the row of hist_data and to use it as a comparaison variable for each rows that contains new_data.

 

I was thinking of creating the new columns in the new_data dataset, but I don't know how to retrieve the data from hist_data into new_data.

 

Example:

hist_data contains:

mean = 117.8

min = 112.3

max = 122.5

..

 

I would like to add new columns into new_data as is :

hist_mean = 117.8

hist_mean = 112.3

hist_mean = 122.5

 

And to repeat those observations for each row that contains new_data.

 

Is there a way to do that?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's one way:

 

data want;
if _n_=1 then set hist_data (rename=(mean=hist_mean min=hist_min max=hist_max));
set new_data;
run;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

Here's one way:

 

data want;
if _n_=1 then set hist_data (rename=(mean=hist_mean min=hist_min max=hist_max));
set new_data;
run;
jpprovost
Quartz | Level 8
But the condition if _n_ = 1 would do it only the line 1?
I want all those datas to be copied for all rows of new_data...
Reeza
Super User

@jpprovost wrote:
But the condition if _n_ = 1 would do it only the line 1?
I want all those datas to be copied for all rows of new_data...

Try it and see. 

Astounding
PROC Star

Yes, the first SET statement executes only once, and reads in the historical values only once.

 

However, variables read from a SAS data set are automatically retained.  So the values just sit there as the second SET statement reads in each observation from the new data set.

 

As you were advised, try it and see.

jpprovost
Quartz | Level 8

@Astounding wrote:

Yes, the first SET statement executes only once, and reads in the historical values only once.

 

However, variables read from a SAS data set are automatically retained.  So the values just sit there as the second SET statement reads in each observation from the new data set.

 

As you were advised, try it and see.


 

I will.

EDIT: Tried and it works. Thanks @Astounding !

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 4198 views
  • 2 likes
  • 3 in conversation