data a;
a='1234-01';
b=input(a,best12.);
run;
I need to convert '1234-01' to number format like 1234-01 . Please help.
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
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.
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.
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
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!
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.