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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3 replies
  • 257 views
  • 1 like
  • 4 in conversation