BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alexx1
Calcite | Level 5
 
I select observations by referencing the variable ( placebo='yes' ) from original data set,
then I output the selected data to a new data set named cert.drug1h
however, the new data set didn't have any observation.
Did I do something wrong?
Can someone help to check if there are any errors...
Thanks!
libname cert '/folders/myfolders/cert';
 
data cert.drug1h(drop=placebo);
     set cert.cltrials(drop=triglyc uric);
     if placebo='yes';
run;
proc print data=cert.drug1h;
run;
 
the log said:

 

NOTE: There were 7 observations read from the data set CERT.CLTRIALS.
NOTE: The data set CERT.DRUG1H has 0 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.07 seconds
cpu time 0.02 seconds
 
 
78 proc print data=cert.drug1h;
79 run;
 
NOTE: No observations in data set CERT.DRUG1H.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @alexx1 and welcome to the SAS Support Communities!

 

You need to develop confidence in handling SAS datasets. They are not "black boxes." Learn how to use SAS procedures (such as CONTENTS, PRINT, FREQ and MEANS) and the DATA step to explore their structure and content.

 

In your example the log has informed you that none of the seven observations in dataset CERT.CLTRIALS meets the condition placebo='yes'. If you didn't expect this, your immediate reaction should be to look into CERT.CLTRIALS and find out what is contained in variable placebo. Knowing (from the log) that the dataset has only a few observations and variables, it is safe to print it entirely:

proc print data=cert.cltrials;
run;

The output from this step will already clarify things in most situations. For example, you might see that all seven values of placebo are 'no' or missing or just single letters such as 'y' or coded as '0', '1'. Or you'll realize that the values are written in upper case or mixed case ('YES', 'Yes') so that your IF condition should read

if lowcase(placebo)='yes';

(I assume that placebo is a character variable because otherwise the log would have contained additional notes like "Invalid numeric data" before the notes you've shown.)

 

Only if the output shows at least one 'yes', you need to investigate further: Is there a format associated with variable placebo? Use PROC CONTENTS to find out:

proc contents data=cert.cltrials;
run;

If so, extend the PROC PRINT step to

proc print data=cert.cltrials;
format placebo;
run;

so that it reveals the unformatted values, which you can then use in the IF condition.

 

Otherwise, leading blanks (' yes') or other invisible characters may be the reason why your IF condition didn't select anything. In this case you can use the COMPRESS function to remove those characters, e.g.

if compress(placebo,,'kn')='yes';

But it's unlikely that you'll need to go that far.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @alexx1 and welcome to the SAS Support Communities!

 

You need to develop confidence in handling SAS datasets. They are not "black boxes." Learn how to use SAS procedures (such as CONTENTS, PRINT, FREQ and MEANS) and the DATA step to explore their structure and content.

 

In your example the log has informed you that none of the seven observations in dataset CERT.CLTRIALS meets the condition placebo='yes'. If you didn't expect this, your immediate reaction should be to look into CERT.CLTRIALS and find out what is contained in variable placebo. Knowing (from the log) that the dataset has only a few observations and variables, it is safe to print it entirely:

proc print data=cert.cltrials;
run;

The output from this step will already clarify things in most situations. For example, you might see that all seven values of placebo are 'no' or missing or just single letters such as 'y' or coded as '0', '1'. Or you'll realize that the values are written in upper case or mixed case ('YES', 'Yes') so that your IF condition should read

if lowcase(placebo)='yes';

(I assume that placebo is a character variable because otherwise the log would have contained additional notes like "Invalid numeric data" before the notes you've shown.)

 

Only if the output shows at least one 'yes', you need to investigate further: Is there a format associated with variable placebo? Use PROC CONTENTS to find out:

proc contents data=cert.cltrials;
run;

If so, extend the PROC PRINT step to

proc print data=cert.cltrials;
format placebo;
run;

so that it reveals the unformatted values, which you can then use in the IF condition.

 

Otherwise, leading blanks (' yes') or other invisible characters may be the reason why your IF condition didn't select anything. In this case you can use the COMPRESS function to remove those characters, e.g.

if compress(placebo,,'kn')='yes';

But it's unlikely that you'll need to go that far.

alexx1
Calcite | Level 5
Thank you very much! I use ( if lowcase(placebo)='yes';) and successfully output the data. Cause variable 'placebo' has upper case! Thank you!!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 888 views
  • 1 like
  • 2 in conversation