BookmarkSubscribeRSS Feed
thelearner
Calcite | Level 5

I have a excel file in which i have a column as policy no in this way-

 

polnr

786543,0786543

957432,00957432

0746352,746352

937526,000937526

X04578,0X04578

 

I want to add a condition in my code which will make 4 combinations of each policy no such as with no zero,with 1 leading zero,with 2 leading zero and 3 leading zero.no matter what combinations it has i just want this 4 combinations.

i made a below code but it isnt working for these.just for the ref here it is

 

data ds2;
length pol $100;
set ds;
if (anydigit(pol)<1) then output;
else do;
do while(char(pol,1)='0');
pol=substrn(pol,2);
end;
output;
pol="0"||strip(pol);
output;
pol="0"||strip(pol);
output;
pol="0"||strip(pol);
output;
end;
run;

 

please help me.

 

Regards:)

 

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

One Way..

 

data have;
input polnr $;
datalines;
786543
0786543
957432
00957432
0746352
746352
937526
000937526
X04578
0X04578
;

data want(drop=i);
   set have;
   pol =polnr;
   output;
   do i=1 to 3;
      pol =cats('0', pol );
      output;
   end;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please post test data in the form of a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

And what you want to see out at the end.  Its hard to guess what you have /want?  I.e. you could have/want:

data have;
  length polnr $20;
  input polnr $;
datalines;
786543
0786543
;
run;

data want;
  set have;
  array res{4} $20;
  do i=1 to 4;
    res{i}=cats(repeat("0",i),polnr);
  end;
run;
thelearner
Calcite | Level 5

i have 2 different combination in same column separated by ',' in one single line in excel.and from those 2 combination i want to make 4 different combination.

no matter how many combinations i have i just want to make it 4

 

PeterClemmensen
Tourmaline | Level 20

Just to be sure then.. So if you have one record with two combinations with 0 and 2 leading zeros respectively, then you want to add two extra combinations with 1 and 3 leading zeros respectively, correct?

thelearner
Calcite | Level 5

exactly.but in the same line itself.which should be separated by ','.as its an excel file.

PeterClemmensen
Tourmaline | Level 20

Can I assume that your data is representative? Or can you also have 0 combinations? Or 1? Or all 4?

thelearner
Calcite | Level 5

yes it my have any combination.may be 1 or may be 2 or 3 or 4 as well.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post have dataset as a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Post what you want out from this data.  Not going to guess any further.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 1196 views
  • 0 likes
  • 3 in conversation