BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Solly7
Pyrite | Level 9

Hi, i have extracted characters(from 6th character till the last one) from numeric variable(account_number) and stored the results in new variable Acct_no from below logic, after that i did summation of trns_amt & trns_volume variables and grouped by the new variable Acct_no .

 

before using substring i had 16 digits on account_number variable(e,g 4000061234567890) and my new variable Acct_no had the result 61234567890 which is what i wanted.

Now i am having an issue on my summary data, the variable Acct_no excludes the first digit(which is 6 in this instance), for example it returns(1234567890) and omit 6

 

proc sql;
   create table acct_extract as
   select *,
       SUBSTR(put(CH_ACCT_NO,best32.-L),6) as Acct_no
   from ccpos_trns
;quit;

PROC SQL ;
 create table credit_total_spnt as
 select Acct_no,
        sum(TRNS_AMT) as Total_Amt,
		sum(TRNS_VOLUME) as Total_Trns
 from acct_extract
 group by Acct_no
 ;quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I can't duplicate your problem. Please provide a portion of your real data which illustrates the problem, as working SAS data step code (Instructions), and not in any other format.

 

data have;
    CH_ACCT_NO=4000061234567890;
    trns_amt=7;
    trns_volume=120;
run;

proc sql;
   create table acct_extract as
   select *,
       SUBSTR(put(CH_ACCT_NO,best32.-L),6) as Acct_no
   from have
;quit;

PROC SQL ;
 create table credit_total_spnt as
 select Acct_no,
        sum(TRNS_AMT) as Total_Amt,
		sum(TRNS_VOLUME) as Total_Trns
 from acct_extract
 group by Acct_no
 ;quit;

  

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I can't duplicate your problem. Please provide a portion of your real data which illustrates the problem, as working SAS data step code (Instructions), and not in any other format.

 

data have;
    CH_ACCT_NO=4000061234567890;
    trns_amt=7;
    trns_volume=120;
run;

proc sql;
   create table acct_extract as
   select *,
       SUBSTR(put(CH_ACCT_NO,best32.-L),6) as Acct_no
   from have
;quit;

PROC SQL ;
 create table credit_total_spnt as
 select Acct_no,
        sum(TRNS_AMT) as Total_Amt,
		sum(TRNS_VOLUME) as Total_Trns
 from acct_extract
 group by Acct_no
 ;quit;

  

--
Paige Miller
Kurt_Bremser
Super User

If CH_ACCT_NO is stored as a number, this needs to be rectified first, at the point where the data is read into the SAS environment. Account "numbers" are not numbers used for calculations, they are just codes, which m7st be stored as character. In the moment they exceed 15 decimal digits, the limits of numerical precision will kick in and lead to unpredictable and wrong results.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 706 views
  • 2 likes
  • 3 in conversation