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

the data set contains many variable of character and numeric types  but i need to print only those number having length equals 12 and it should be numbers.

kindly help.(No macros)

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Or the other possibility being eliminate non digit values using compress and filter based on length

 


data a;

input id $30.;

cards;
123456789012
1234567890qa
123456
asdghjj098752
123456789087654
run;

data want;
set a;
if  length(compress(strip(id),,'kd'))=12;
run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Hi @asuman Can you post a sample along with your description plz

asuman
Obsidian | Level 7

data a;

input id;

cards;

123456789012

1234567890qa

123456

asdghjj098752

123456789087654

run;

 

need to print only those records having length=12 and it should be numbers only.

novinosrin
Tourmaline | Level 20

Are you after this?

 

data a;

input id $30.;

cards;
123456789012
1234567890qa
123456
asdghjj098752
123456789087654
run;

data want;
set a;
if notdigit(strip(id))=0 and length(strip(id))=12;
run;
novinosrin
Tourmaline | Level 20

Or the other possibility being eliminate non digit values using compress and filter based on length

 


data a;

input id $30.;

cards;
123456789012
1234567890qa
123456
asdghjj098752
123456789087654
run;

data want;
set a;
if  length(compress(strip(id),,'kd'))=12;
run;
asuman
Obsidian | Level 7

Both solutions works perfectly.

thanks novinosrin.

Regards,

aditya suman

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 5 replies
  • 2276 views
  • 0 likes
  • 2 in conversation