Modifying Serial numbers in sas data set

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 87
Accepted Solution

Modifying Serial numbers in sas data set

how to get first DACODE and serial number in order

i am using following code


data detaisl;
input DACODE $ 7. date yymmdd10. serial_no;
format date yymmdd10.;
datalines;
1230005 20130430 0001
1230005 20130430 0002
1230005 20130430 0003
1230005 20130430 0004
1230005 20130430 0005
1230005 20130430 0006
1230005 20130430 0007
1230005 20130430 0008
1230005 20130430 0009
1230005 20130430 0010
1230005 20130430 0011
1230005 20130430 0012
1230005 20130430 0013
1230005 20130430 0014
1230005 20130430 0015
1230006 20130430 0001
1230006 20130430 0002
1230006 20130430 0003
1230006 20130430 0004
1230006 20130430 0005
1230006 20130430 0006
1230006 20130430 0007
1230006 20130430 0008
1230006 20130430 0009
1230006 20130430 0010
1230006 20130430 0011
1230006 20130430 0012
1230006 20130430 0013
1230006 20130430 0014
1230006 20130430 0015
;
run;

proc format;
picture amt low-high = '0000' (fill='0000');
run;

proc print data=detaisl;
format  serial_no amt.;
run;

here serial_no i want to update serial_no
if serial_no is greater than 0009 then next serial_no ie 0010 must be 0001

eg i want output like this

1230005 20130430 0001
1230005 20130430 0002
1230005 20130430 0003
1230005 20130430 0004
1230005 20130430 0005
1230005 20130430 0006
1230005 20130430 0007
1230005 20130430 0008
1230005 20130430 0009
1230005 20130430 0001
1230005 20130430 0002
1230005 20130430 0003
1230005 20130430 0004
1230005 20130430 0005
1230005 20130430 0006
1230006 20130430 0001
1230006 20130430 0002
1230006 20130430 0003
1230006 20130430 0004
1230006 20130430 0005
1230006 20130430 0006
1230006 20130430 0007
1230006 20130430 0008
1230006 20130430 0009
1230006 20130430 0001
1230006 20130430 0002
1230006 20130430 0003
1230006 20130430 0004
1230006 20130430 0005
1230006 20130430 0006



Accepted Solutions
Solution
‎05-28-2013 08:05 AM
Respected Advisor
Posts: 3,799

Re: Modifying Serial numbers in sas data set

I thing MOD function is the key.  Many variations on how you use the result of MOD.

data detaisl;
   input DACODE :$7. date :yymmdd10. serial_no;
   retain d 9;
   m=mod(serial_no,d);
   newserial = ifn(m,m,d,
.);
   format date yymmdd10. serial_no newserial z4.;
  
*drop d m;
  
datalines;
1230005 20130430 0001
1230005 20130430 0002
1230005 20130430 0003
1230005 20130430 0004
1230005 20130430 0005
1230005 20130430 0006
1230005 20130430 0007
1230005 20130430 0008
1230005 20130430 0009
1230005 20130430 0010
1230005 20130430 0011
1230005 20130430 0012
1230005 20130430 0013
1230005 20130430 0014
1230005 20130430 0015
1230006 20130430 0001
1230006 20130430 0002
1230006 20130430 0003
1230006 20130430 0004
1230006 20130430 0005
1230006 20130430 0006
1230006 20130430 0007
1230006 20130430 0008
1230006 20130430 0009
1230006 20130430 0010
1230006 20130430 0011
1230006 20130430 0012
1230006 20130430 0013
1230006 20130430 0014
1230006 20130430 0015
;;;;
   run;

View solution in original post


All Replies
Super Contributor
Posts: 276

Re: Modifying Serial numbers in sas data set

Hi Santhosh.



Try this..

         

     Data Test(drop=a) ;

          set detaisl;

     a=int(serial_no/9);

          if serial_no gt 9 then serial_no=serial_no-9*a;

          else serial_no=serial_no;

          if serial_no-9*a=0 then serial_no=9;

          run;

        

Regards.

Sanjeev.K

Solution
‎05-28-2013 08:05 AM
Respected Advisor
Posts: 3,799

Re: Modifying Serial numbers in sas data set

I thing MOD function is the key.  Many variations on how you use the result of MOD.

data detaisl;
   input DACODE :$7. date :yymmdd10. serial_no;
   retain d 9;
   m=mod(serial_no,d);
   newserial = ifn(m,m,d,
.);
   format date yymmdd10. serial_no newserial z4.;
  
*drop d m;
  
datalines;
1230005 20130430 0001
1230005 20130430 0002
1230005 20130430 0003
1230005 20130430 0004
1230005 20130430 0005
1230005 20130430 0006
1230005 20130430 0007
1230005 20130430 0008
1230005 20130430 0009
1230005 20130430 0010
1230005 20130430 0011
1230005 20130430 0012
1230005 20130430 0013
1230005 20130430 0014
1230005 20130430 0015
1230006 20130430 0001
1230006 20130430 0002
1230006 20130430 0003
1230006 20130430 0004
1230006 20130430 0005
1230006 20130430 0006
1230006 20130430 0007
1230006 20130430 0008
1230006 20130430 0009
1230006 20130430 0010
1230006 20130430 0011
1230006 20130430 0012
1230006 20130430 0013
1230006 20130430 0014
1230006 20130430 0015
;;;;
   run;
Super Contributor
Posts: 276

Re: Modifying Serial numbers in sas data set

Posted in reply to data_null__

Hi    

Yes,you are right.

MOD function is right selection then INT.

and just curious how you are posting the SAS code with syntax colors ?? since i am trying to display my SAS code but i can't.

Regards.

Sanjeev.K

Respected Advisor
Posts: 3,799

Re: Modifying Serial numbers in sas data set

Posted in reply to kuridisanjeev

From SAS EG right click <copy HTML Source to clip board>

in Forum editor click HTML

Past copied HTML source

Click "show full editor" to return to regular mode.

Respected Advisor
Posts: 3,156

Re: Modifying Serial numbers in sas data set

Posted in reply to kuridisanjeev

If EG is not included in your BASE SAS installation, try to use MS WORD as a middleman.

Haikuo

Super Contributor
Posts: 276

Re: Modifying Serial numbers in sas data set

Hi

I have base SAS 9.2 installed in my PC. How can i use MS WORD ???

Could you please explain me..

Regards.

Sanjeev.K

Respected Advisor
Posts: 3,156

Re: Modifying Serial numbers in sas data set

Posted in reply to kuridisanjeev

, Sorry about being not sufficiently clear. What I mean is: COPY your BASE code, then PASTE into MS WORD, then do it again, COPY from WORD, then PASTE into your post.

Super Contributor
Posts: 276

Re: Modifying Serial numbers in sas data set

Thanks A lot ..

working perfectly...

     Data isay;

      thanks="A lot";

           run;

      proc print;

      run;


:-) :-)



Regards..

Sanjeev.K

Super User
Posts: 19,770

Re: Modifying Serial numbers in sas data set

Posted in reply to kuridisanjeev

Or just use FireFox. I haven't tried Chrome but Safari does keep the colour as well.

Super Contributor
Posts: 276

Re: Modifying Serial numbers in sas data set

Not working in FireFox as well...:-(

Super Contributor
Posts: 276

Re: Modifying Serial numbers in sas data set

Hi  haikuo bian


But why SAS is not listed in SYNTAX HIGHLIGHTING  ????

All other programming languages available in that list except SAS.That too in SAS fourm..

Feeling strange.....!!!!!!!!!!!!!!!!!!!!!!


🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 410 views
  • 3 likes
  • 5 in conversation