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

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/
;   

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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/
;  

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Use informat, not format, in the data step.

--
Paige Miller
ballardw
Super User

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/
;  
ybz12003
Rhodochrosite | Level 12
What's the comma15. mean?
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Tom
Super User Tom
Super User

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/
; 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 452 views
  • 1 like
  • 4 in conversation