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

Hi!  I'm trying to find the unique identifiers that correspond to when the flag variable I made=1.  I haven't been able to find a way to write a proc print of ID if flag=1? I basically want a list of the IDs when flag=1

 

Sample Data:

ID            Flag

1                1

2                0

3                0

4                1

 

Enterprise Guide will not allow this:

 

proc print data=clean2;
      where Flag=1;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
proc print data=have;
   where flag=1;
run;

View solution in original post

10 REPLIES 10
novinosrin
Tourmaline | Level 20

Are you seriously asking how to write a where statement in proc print?

 

data have;
input ID            Flag ;
cards;
1                1
2                0
3                0
4                1
;
proc print;
where flag=1;
run;
jmmedina25
Obsidian | Level 7

No. I'm asking because I only want the ID to print (there are a dozen other variables) and this code will not run:

 

proc print data=clean2;
    var ID;
    where flag=1;
run;

 

or even this code:

 

proc print data=clean2;
    where flag=1;
run;

 

A 'where' statement is not compatible with the proc print command. 

jmmedina25
Obsidian | Level 7

This is in Enterprise Guide, which may be why.

PeterClemmensen
Tourmaline | Level 20

What does your log say?

Astounding
PROC Star

Both of these programs are perfectly fine, whether using EG or not.  Here are some issues to look for.

 

Is FLAG actually a character variable?  Then you would need to use:

 

where flag="1";

 

Does FLAG exist in CLEAN2 or was it created and then dropped?

jmmedina25
Obsidian | Level 7

Thank you, I actually just realized that for the flag variable I was running there were no flags that=1, they were all =0, therefore there was no output.

PeterClemmensen
Tourmaline | Level 20
proc print data=have;
   where flag=1;
run;
jmmedina25
Obsidian | Level 7

This code will not run in Enterprise Guide; not sure why?

andreas_lds
Jade | Level 19
Look at the log! If you don't understand the log, post it here using the {i} icon to preserve formatting.
jmmedina25
Obsidian | Level 7

Thanks, it wasn't working because there were no values of the flag variable that=1, they all =0.  Still confused why the code was red but whatever.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 10 replies
  • 2175 views
  • 1 like
  • 5 in conversation