BookmarkSubscribeRSS Feed
farshidowrang
Quartz | Level 8

Dear friends,

 

I need to perform linear interpolations

 

I do it correctly when I have only one dataset in one table

 

However, I have many many different datasets in one table and each dataset should have its own interpolation curve

 

Let's look at a simple example with only two datasets (A & B):

 

NAMEDEPTHXY
A0,00496323,566277756,14
 0,50,,
 1,00,,
 1,50,,
 2,00,,
 2,50,,
 3,00,,
 3,50,,
 4,00,,
 4,50,,
 5,00,,
 5,50,,
 6,00,,
A6,50496210,946277828,15
 7,00,,
 7,50,,
 8,00,,
 8,50,,
 9,00,,
 9,50,,
 10,00,,
 10,50,,
A11,00496210,876277828,25
B0,00516239.553476247816.3269
 0.5  
 1,00  
 1,50  
 2,00  
 2,50  
 3,00  
 3,50  
 4,00  
 4,50  
 5,00  
 5,50  
B6,00516239.553476247816.3269
 6,50  
 7,00  
 7,50  
 8,00  
 8,50  
B9,00516239.515346247816.3202
 9,50  
 10,00  
 10,50  
 11,00  
 11,50  
 12,00  
B12,50516239.479666247816.3124

 

I use the following proc procedure to perform linear regression for one dataset:

 

proc expand data=&_INPUT1 out=&_OUTPUT1;
convert X=linear_X / method=join;
id DEPTH;
run;

 

proc expand data=&_INPUT1 out=&_OUTPUT1;
convert Y=linear_Y / method=join;
id DEPTH;
run;

 

The interpolation will fill the missing values for X and Y

 

However, when I have two datasets (in this case A & B) or more I can't use this formula

 

I know I need some kind of DO LOOP somewhere but I don't know where and how I should use it

 

Can you please help me with it? 

 

Thank you vey much! 

 

Best regards

 

Farshid 

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Does this help you?

 

data have;
input NAME $ (DEPTH X Y)(:comma18.4);
infile datalines dsd dlm='|';
datalines;
A|0,00 |496323,56   |6277756,14
 |0,50 |            |
 |1,00 |            |
 |1,50 |            |
 |2,00 |            |
 |2,50 |            |
 |3,00 |            |
 |3,50 |            |
 |4,00 |            |
 |4,50 |            |
 |5,00 |            |
 |5,50 |            |
 |6,00 |            |
A|6,50 |496210,94   |6277828,15
 |7,00 |            |
 |7,50 |            |
 |8,00 |            |
 |8,50 |            |
 |9,00 |            |
 |9,50 |            |
 |10,00|            |
 |10,50|            |
A|11,00|496210,87   |6277828,25
B|0,00 |516239.55347|6247816.3269
 |0.5  |            | 
 |1,00 |            | 
 |1,50 |            | 
 |2,00 |            | 
 |2,50 |            | 
 |3,00 |            | 
 |3,50 |            | 
 |4,00 |            | 
 |4,50 |            | 
 |5,00 |            | 
 |5,50 |            | 
B|6,00 |516239.55347|6247816.3269
 |6,50 |            | 
 |7,00 |            | 
 |7,50 |            | 
 |8,00 |            | 
 |8,50 |            | 
B|9,00 |516239.51534|6247816.3202
 |9,50 |            | 
 |10,00|            | 
 |10,50|            | 
 |11,00|            | 
 |11,50|            | 
 |12,00|            | 
B|12,50|516239.47966|6247816.3124
;

data temp(drop=_:);
   set have;
   if not missing(Name) then _Name=Name;
   Name=coalescec(Name, _Name);
   retain _Name;
run;

proc sort data=temp;
   by Name DEPTH;
run;

proc expand data=temp out=want;
   by Name;
   id DEPTH;
   convert X=linear_X / method=join;
   convert Y=linear_Y / method=join;
run;

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 388 views
  • 0 likes
  • 2 in conversation