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

data a;
a='1234-01';
b=input(a,best12.);
run;

 

I need to convert '1234-01' to number format like 1234-01 . Please help.

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

If you store the variable as a number you can insert the dash when displaying the number by designing your own format.  Let's assume you store you numbers as whole number that can take up to six digits, as in:

 

 

proc format; 
  picture myfmti other='9999-99';
run;

data w;   
  format x myfmti.;
  do x=123456,23456,3456;
    put "Numeric " x=comma7.0 " formatted " x=;
  end;
run;

 

which results in:

458  data w;
459    format x myfmti.;
460    do x=123456,23456,3456;
461      put "Numeric " x=comma7.0 " formatted " x=;
462    end;
463  run;

Numeric x=123,456  formatted x=1234-56
Numeric x=23,456  formatted x=0234-56
Numeric x=3,456  formatted x=0034-56

 

 

 

 

Instead of storing integers, it might be psychologically easier to store the number as 1234.56, and make a format such that a dash replaces the decimal in the printed value, as in:

 

proc format;
  picture myfmtd  other='9999-99' (multiplier=100);run;
data w;
  format x myfmtd.;
  do x=1234.56,234.56,34.56;
    put "Numeric " x=7.2 " formatted " x=;
  end;
run;

which generates:

467  data w;
468    format x myfmtd.;
469    do x=1234.56,234.56,34.56;
470      put "Numeric " x=7.2 " formatted " x=;
471    end;
472  run;

Numeric x=1234.56  formatted x=1234-56
Numeric x=234.56  formatted x=0234-56
Numeric x=34.56  formatted x=0034-56

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

7 REPLIES 7
Reeza
Super User
That's not a number. What do you want to happen with the dash?
West26
Obsidian | Level 7

Well, one set of case numbers are in character format and other set are in numeric format. I need to combine both to one set.

I agree with your statement. Dash has to be included, but now I believe it is not possible.

Thank you.

ballardw
Super User

You may want to show us the results of Proc Contents on that "other set" and tell us which of the variables is supposed to match "1234-01" numerically.

Reeza
Super User
Your numeric values will not have a dash unless they have a custom format applied. If that's the case you can strip the dash and use a direct merge. Either way you need to make one look like the other but you've only shown what one value looks like.
West26
Obsidian | Level 7
Hi Reeza,
Thanks for taking time and providing the insights into the issue. The values which have a dash were stored as characters only. I'm able to merge all of those, except the ones with dash. I can't make the other set which is already in numeric format, as character format and merge both, as I need to a lot of count and order by later on. Will try formatting them for now, and see what will happen.

Thanks,
Ravindra
Reeza
Super User
Count and order by don’t require numeric variables.
mkeintz
PROC Star

If you store the variable as a number you can insert the dash when displaying the number by designing your own format.  Let's assume you store you numbers as whole number that can take up to six digits, as in:

 

 

proc format; 
  picture myfmti other='9999-99';
run;

data w;   
  format x myfmti.;
  do x=123456,23456,3456;
    put "Numeric " x=comma7.0 " formatted " x=;
  end;
run;

 

which results in:

458  data w;
459    format x myfmti.;
460    do x=123456,23456,3456;
461      put "Numeric " x=comma7.0 " formatted " x=;
462    end;
463  run;

Numeric x=123,456  formatted x=1234-56
Numeric x=23,456  formatted x=0234-56
Numeric x=3,456  formatted x=0034-56

 

 

 

 

Instead of storing integers, it might be psychologically easier to store the number as 1234.56, and make a format such that a dash replaces the decimal in the printed value, as in:

 

proc format;
  picture myfmtd  other='9999-99' (multiplier=100);run;
data w;
  format x myfmtd.;
  do x=1234.56,234.56,34.56;
    put "Numeric " x=7.2 " formatted " x=;
  end;
run;

which generates:

467  data w;
468    format x myfmtd.;
469    do x=1234.56,234.56,34.56;
470      put "Numeric " x=7.2 " formatted " x=;
471    end;
472  run;

Numeric x=1234.56  formatted x=1234-56
Numeric x=234.56  formatted x=0234-56
Numeric x=34.56  formatted x=0034-56

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1004 views
  • 2 likes
  • 4 in conversation