Hi Sas Forum,
I Have the attahced k_1 data set.
I wanted to create a flag with the following condition.
if STATUS in("CURRENT") then Delq_Flag=0;
else Delq_Flag=1;
So, I used below code.
data k_3;
set k_1;
if STATUS in("CURRENT") then Delq_Flag=0;
else Delq_Flag=1;
run;
Q: But above code doesn't give correct results although the logic seems correct. But below code provides the intended resutls. I cannot understand what is happening. Coudl someone help me to understand.
data k_2;
set k_1;
if index(STATUS,"CURRENT") then Delq_Flag=0;
else Delq_Flag=1;
run;
Thanks
Miris
In SAS trailing blanks are meaningless, but leading blanks can cause these type of behavior. Leading blanks can be hard to see are they normally do not appear when using PUT as it will trim them. You can see them better if you use the $QUOTE. format.
data k_2;
set k_1;
if index(STATUS,"CURRENT") and not STATUS in ("CURRENT") then put status $quote. ;
run;
Your dataset is protected, probably for good reason.
Run a proc freq on your variable of interest. Most likely it has trailing blanks or some other letters that cause it not to be an exact match.
ie
Current is not equal to "Current " (3 extra spaces)
but the index function would return a match.
EDIT: Trailing blanks are not an issue, Leading Blanks would cause a mismatch.
Are you sure?
Thanks Tom and John for the corrections.
Only leading blanks are an issue.
H Tom, Reeza and Data_null,
Many thanks to each one of you for this contribution.
Regards
Miris
In SAS trailing blanks are meaningless, but leading blanks can cause these type of behavior. Leading blanks can be hard to see are they normally do not appear when using PUT as it will trim them. You can see them better if you use the $QUOTE. format.
data k_2;
set k_1;
if index(STATUS,"CURRENT") and not STATUS in ("CURRENT") then put status $quote. ;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.