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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 458 views
  • 3 likes
  • 3 in conversation