I have this data:
data have;
input test $25. ;
cards;
0 | 0 | 0 | 0 | 0
0 | 1 | 0
1
2
0 | 24 | 0
0 | 0 | 0 | 23
0 | 0| 23 | 24 | 1
0 | 0
0 | 0 | 1
0
27
;
run;
And I want to have this:
data want;
input test $22. want 4. ;
cards;
0 | 0 | 0 | 0 | 0 1
0 | 1 | 0 0
1 0
2 0
0 | 24 | 0 0
0 | 0 | 0 | 23 0
0 | 0 | 23 | 24 | 1 0
0 | 0 1
0 | 0 | 1 0
0 1
27 0
;
run;
The values were separated by " | " and I need to find what obs that have ONLY zero. I tried to use a couple of procedures but NONE seems working properly. If anyone can help I would highly appreciate!
Best,
Le
data have;
input test $25. ;
cards;
0 | 0 | 0 | 0 | 0
0 | 1 | 0
1
2
0 | 24 | 0
0 | 0 | 0 | 23
0 | 0| 23 | 24 | 1
0 | 0
0 | 0 | 1
0
27
;
run;
proc print;
run;
data want;
set have;
want=^lengthn(compress(test,"0|","s"));
run;
proc print;
run;
data have;
input test $25. ;
cards;
0 | 0 | 0 | 0 | 0
0 | 1 | 0
1
2
0 | 24 | 0
0 | 0 | 0 | 23
0 | 0| 23 | 24 | 1
0 | 0
0 | 0 | 1
0
27
;
run;
proc print;
run;
data want;
set have;
want=^lengthn(compress(test,"0|","s"));
run;
proc print;
run;
For having some fun.
data have;
input test $25. ;
cards;
0 | 0 | 0 | 0 | 0
0 | 1 | 0
1
2
0 | 24 | 0
0 | 0 | 0 | 23
0 | 0| 23 | 24 | 1
0 | 0
0 | 0 | 1
0
27
;
run;
data want;
set have;
want=verify(test,"0| ")=0;
run;
proc print;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.