BookmarkSubscribeRSS Feed
user24
Obsidian | Level 7

I want to append these codes in one proc sql statement. Is that possible?

 

Is that possible with union or union corr?

 


PROC SQL; CREATE TABLE SGBSTDN AS
SELECT DISTINCT SGBSTDN_PIDM AS PIDM,
'Student' as StatusStudent
FROM STG.SGBSTDN
ORDER BY PIDM
;QUIT;

 

PROC SQL; CREATE TABLE SARADAP AS
SELECT DISTINCT SARADAP_PIDM AS PIDM,
'Applicant' as StatusApplicant
FROM STG.SARADAP
ORDER BY PIDM
;QUIT;

data STUDENT_PIDM;
merge SGBSTDN SARADAP ;
by pidm;
run;

data student_pidm2;
set student_pidm;
if StatusStudent='' then StatusStudent='Applicant';
run;

 

proc sql;
create table STUDENT as
select distinct pidm,
StatusStudent,
case
when b.Spbpers_sex IS NULL then "N"
when b.Spbpers_sex ='N' then "N"

when b.Spbpers_sex ='F' then "F"
when b.Spbpers_sex ='M' then "M"
END AS GENDER

from work.student_pidm2 as a left join stg.spbpers as b
on b.spbpers_pidm=a.pidm ;
quit;

 

Please let me know if it is possible?

4 REPLIES 4
Reeza
Super User

@user24 wrote:

I have a bunch of codes. I want to make them together in one sql sel code

Is that possible with union or union corr?

 


What are you trying to do? Combine all your 3 SQL to one step?

Append all the tables together that you created?

user24
Obsidian | Level 7

Yes, i want to append them in one step. Sorry if i couldn't explain

Kurt_Bremser
Super User

Over time, I have come to the conclusion that having several simple steps instead of one complicated step is easier to maintain and usually more performant. This is particularly true when working with PROC SQL.

LinusH
Tourmaline | Level 20
I think that you could put the last data step and the last SQL in one SQL.
Replace your IF and CASE statements with the coalesce() function to make your code easier and with less hard coding.
Data never sleeps

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1139 views
  • 0 likes
  • 4 in conversation