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;
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 16. Read more here about why you should contribute and what is in it for you!
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.