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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15
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;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

4 REPLIES 4
yabwon
Onyx | Level 15
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;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



binhle50
Obsidian | Level 7
Awesome! Thanks so much. It works perfectly
Ksharp
Super User

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;

Ksharp_0-1683724088535.png

 

binhle50
Obsidian | Level 7
Wow that is fun. Awesome! Thanks!

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 4 replies
  • 967 views
  • 3 likes
  • 3 in conversation