DATA Step, Macro, Functions and more

Append some codes in one proc sql statement

Reply
Contributor
Posts: 33

Append some codes in one proc sql statement

[ Edited ]

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?

Super User
Posts: 17,907

Re: Make one code from bunch of them with union sql sel


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?

Contributor
Posts: 33

Re: Make one code from bunch of them with union sql sel

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

Super User
Posts: 6,963

Re: Make one code from bunch of them with union sql sel

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,260

Re: Append some codes in one proc sql statement

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
Ask a Question
Discussion stats
  • 4 replies
  • 310 views
  • 0 likes
  • 4 in conversation