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

Hello,

 

I'm trying to select all observations where flag is not equal to 'Y' in the previously and set those to Y in the current data pull. It felt like a simple logic, but I don't seem to be getting the right answer. Appreciate the help in helping me understand what am I doing wrong here.

 

Input data provided in code.

 

Expected output:

Capturee.PNG

 

Output received:

Capturee.PNG

 

my code

data dat1;
 input id $ flag $ new zz;
 cards;
a Y 12 111
b   22 222
c   33 333
 ;
 run;


 proc sql; 
        create table pilot as 
select *, 'Y' as flag
     from dat1 
      	  where flag neq 'Y'; 
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data dat1;
 input id $ flag $ new zz;
 cards;
a Y 12 111
b  . 22 222/*see the correction for period in place of missing values*/
c  . 33 333/*see the correction for period in place of missing values*/
 ;
 run;


 proc sql; 
        create table pilot as 
select id, 'Y' as flag,new ,zz
     from dat1 
      	  where flag ne 'Y'; 
quit;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

data dat1;
 input id $ flag $ new zz;
 cards;
a Y 12 111
b  . 22 222/*see the correction for period in place of missing values*/
c  . 33 333/*see the correction for period in place of missing values*/
 ;
 run;


 proc sql; 
        create table pilot as 
select id, 'Y' as flag,new ,zz
     from dat1 
      	  where flag ne 'Y'; 
quit;
AJ_Brien
Quartz | Level 8
That made it work but isn't char missing value represented by blank and not a '.'? flag is defined as a char here so why are we representing that as a period.
novinosrin
Tourmaline | Level 20

Those values before being read are "RAW" data and not a SAS data set value. basically to read raw data instream with a list input you would need to have periods in punch raw cards data.

 

PS Your definition holds true for default missing values in a dataset

AJ_Brien
Quartz | Level 8
that makes sense. Thank you!
novinosrin
Tourmaline | Level 20

The thread could lead to discussion about "how to read raw data" which is out of scope for the stated objective, but I recommend reading those concepts.

 

You could read the same data as- is with a formatted input  to see the difference

 

data dat1;
 input id $ @3 flag $1. new zz;
 cards;
a Y 12 111
b   22 222
c   33 333
 ;
 run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 932 views
  • 0 likes
  • 2 in conversation