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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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