Hello Everyone! I have two dataset "master" and "child" in my program.
Condition
The child table will only be created if the count of number of record for master table >=3.
I wrote the prog below but don't know how to connect both dataset. Sorry this might be the foolish question as I did not find the solution.
data child;
input empid ename $ job $;
cards;
1001 John clerk
1002 Esten Analyst
1003 Ruakin principal
;
data master;
input pid age gender;
cards;
101 23 1
102 34 5
103 54 6
;
proc sql;
create table cnt_master
as select count(*) as cnt from master;
quit;
data final;
set cnt_master;
if cnt>=3 then output child;
run;
Thanks in advance
I'm not sure what you mean when you say connect. It would also help to provide an exampe of what you want for the final output.
Thank you for looking into the matter.
Out of the two datasets (master and child), the condition is that child dataset can only be created in work library if and only if number of records in master table >=3
e.g. in the above example , As the master dataset contain only 3 record which means it satisfy the condition.
Therefore the child dataset should be created. How to write.
something like below
data master;
input pid age gender;
cards;
101 23 1
102 34 5
103 54 6 ;
proc sql;
create table cnt_master as select count(*) as cnt from master; quit;
data final;
set cnt_master;
if cnt>=3 then output child
( data child;
input empid ename $ job $;
cards;
1001 John clerk
1002 Esten Analyst
1003 Ruakin principal
; )
run;
Is this what you are after?
OPTIONS MPRINT MLOGIC SYMBOLGEN;
DATA MASTER;
INFILE "E:\MASTER.TXT";
INPUT PID AGE GENDER;
RUN;
PROC SQL NOPRINT;
SELECT COUNT(*) INTO: MASTCNT FROM MASTER;
QUIT;
%MACRO IMPORT;
%IF &MASTCNT. >= 3 %THEN %DO;
DATA CHILD;
INFILE "E:\CHILD.TXT";
INPUT EMPID ENAME $ JOB $;
RUN;
%END;
%MEND;
%IMPORT;
Or, to save the macro part:
OPTIONS MPRINT MLOGIC SYMBOLGEN;
DATA MASTER;
INFILE "E:\MASTER.TXT";
INPUT PID AGE GENDER;
RUN;
data _null_;
set sashelp.vtable (where=(libname="WORK" and memname="MASTER" and NOBS > 3));
call execute('data child;
infile "e:\child.txt";
input empid ename $ job $;
run;');
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.