Hello,
I found the sample dataset I created was not the way I wanted. If the number comes with a comma, the dataset didn't show. Please help me to fix it.
data Cost;
Format IDs $10. ED DOLLAR15.2 ICU DOLLAR15.2 Lab DOLLAR15.2;
infile datalines delimiter='/';
input IDs ED ICU Lab;
datalines;
EC1R00002/ 899.28/ / 256.31/
KC1Y00012/ / 11,080.82/ 619.91/
WC1G00013/ 332.34/ 929.71/ 2,066.98/
;
Use the COMMA informat.
data Cost; Format IDs $10. ED DOLLAR15.2 ICU DOLLAR15.2 Lab DOLLAR15.2; inFormat IDs $10. ED ICU Lab comma15.; infile datalines delimiter='/'; input IDs ED ICU Lab; datalines; EC1R00002/ 899.28/ / 256.31/ KC1Y00012/ / 11,080.82/ 619.91/ WC1G00013/ 332.34/ 929.71/ 2,066.98/ ;
Use informat, not format, in the data step.
Use the COMMA informat.
data Cost; Format IDs $10. ED DOLLAR15.2 ICU DOLLAR15.2 Lab DOLLAR15.2; inFormat IDs $10. ED ICU Lab comma15.; infile datalines delimiter='/'; input IDs ED ICU Lab; datalines; EC1R00002/ 899.28/ / 256.31/ KC1Y00012/ / 11,080.82/ 619.91/ WC1G00013/ 332.34/ 929.71/ 2,066.98/ ;
COMMA15. is an informat that reads character string which are numbers with commas in them, up to 15 characters wide. If you don't use COMMA15. or DOLLAR15., then the comma in the number causes problems.
Do NOT indent lines of data. To make it easier to remember do not indent the DATALINES statement either.
You need to use the COMMA informat to be able to read in strings that thousand separators (and $ characters) in them.
Since you seem to have all of the data for one observation on a single line it is probably wisest to add the TRUNCOVER option to prevent the INPUT statement from jumping to the next line if the last value is missing.
Note there is no need to attach the $ format to character variables, SAS already knows how to print character variables. You appear to be using the SIDE EFFECT of the format statement being the first place the variable appears to force SAS to set the storage length of the character variables. It is clearer if you just set the length directly.
data Cost;
infile datalines delimiter='/' truncover;
length IDs $10 ED ICU Lab 8;
format ED ICU Lab DOLLAR15.2;
informat ED ICU Lab comma.;
input IDs ED ICU Lab;
datalines;
EC1R00002/ 899.28/ / 256.31/
KC1Y00012/ / 11,080.82/ 619.91/
WC1G00013/ 332.34/ 929.71/ 2,066.98/
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.