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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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