BookmarkSubscribeRSS Feed
Abraham
Obsidian | Level 7

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

4 REPLIES 4
ballardw
Super User

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.

Abraham
Obsidian | Level 7

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;

Scott_Mitchell
Quartz | Level 8

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;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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