BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data test1;
input id state $15. ;
datalines;
111 Texas
222 Florida
333 Kansas
444 Lowa
555 Louisiana
;
run;

data test2;
input id state $15. ;
datalines;
666 Hawaii
777 Kentucky
888 Maryland
999 Michigan
110 Missouri
;
run;




data test3;
input id state $15. ;
datalines;
112  Montana
113  Neveda
114  New Jersey
115  New York
116  Virgina
;
run;


proc sql ;
    select * from test1 (obs=1) 
    union
    select * from  test3 (obs=1)
    union
    select * from test2 (obs=1);
quit;

How to extract first record from each table using proc sql i tried above code  

monotonic function is undocumented so in this case how to achive with proc sql for N records pull from tables

3 REPLIES 3
Patrick
Opal | Level 21

I would add the ALL keyword to your union but else your SQL looks o.k. to me as long as the source tables are in SAS and not a database.

proc sql ;
    select * from test1 (obs=1) 
    union corr all
    select * from  test3 (obs=1)
    union corr all
    select * from test2 (obs=1);
quit;
LinusH
Tourmaline | Level 20
What is your exact requirement?
Since you are mentioning monotonic, do wish to store the original row number?
If you're not comfortable using montonic, switch to the data step instead (_n_).
And N, does it impliy you wish to use a parameter for the no of observations to pull from each source?
Data never sleeps
ballardw
Super User

I think you need to provide an example of what you expect for output given a value of N other than 1.

 

I have no clue what you are expecting as a result.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 485 views
  • 1 like
  • 4 in conversation