BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
t_ar_taat
Quartz | Level 8

I'm looking for ways to generate new obs from empty dataset(which have 0 obs).

Let's say you have 2 obs in adsl. From this data set, we create 0obs dataset(adsl_empty).

 

After that, please tell me if you know how to generate only 1obs with USUBJID = "No patients"; As I get "0 obs" after executing below sample. I want this to be 1 OBS in "adsl_x" dataset.

 

data work.adsl;
 USUBJID ="xx1";output;
 USUBJID ="xx2";output;
run;

data work.adsl_empty;
 set work.adsl;
delete;
run;

data work.adsl_X;
 set work.adsl_empty;
 USUBJID = "No patients";output;
run;

0obs.jpg

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's a simple DATA step approach:

 

data want;

if 5=4 then set adsl_empty;

USUBJID = 'No Patients';

output;

run;

 

One issue you may need to address is the length of the variable USUBJID.  It has to be at least 11 characters long in ADSL_EMPTY, in order to be able to fit the full text within "No Patients".

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can do it in a variety of ways:

data step - set empty and new dataset with your data in example:

data temp;
  usubjid="No subjects";
run;

data adsl;
  set adsl_blank temp;
run;

proc append - put one dataset under another

proc sql - union all, selelct * from each

proc sql insert into

 

t_ar_taat
Quartz | Level 8
Thank you RW9.
I appreciate your telling me many ways for this.
Astounding
PROC Star

Here's a simple DATA step approach:

 

data want;

if 5=4 then set adsl_empty;

USUBJID = 'No Patients';

output;

run;

 

One issue you may need to address is the length of the variable USUBJID.  It has to be at least 11 characters long in ADSL_EMPTY, in order to be able to fit the full text within "No Patients".

t_ar_taat
Quartz | Level 8
Thank you Astounding.
This way is very simple and clear.
I also care length of USUBJID variable.

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
  • 4726 views
  • 1 like
  • 3 in conversation