Write and run SAS programs in your web browser

which informat I should use?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 112
Accepted Solution

which informat I should use?

data googlestat; 
infile '/folders/myfolders/preprocessedgooglestatstab.txt' dlm='09'x dsd firstobs=2; 
input DayofWeek $ Date MMDDYY10. Impressions 5. Clicks 2. Revenue COMMA10.1; 
run; 
proc print data=googlestat; 
run; 

Hello everyone,

 

I wonder which informat I should use for DayofWeek so the next observation which is the date would not be in the same column as DayofWeek? Thank you!


Accepted Solutions
Highlighted
Solution
‎02-23-2018 05:45 PM
Super User
Super User
Posts: 8,074

Re: which informat I should use?

[ Edited ]

The main thing is to use LIST MODE input statement. So either remove the informats from the INPUT statement, or add : modifier in front of them.

 

You do not need to tell SAS to use an informat to read most values.  Your example has two values where it is useful, a date and number with embedded thousands separators.

 

Your date values (at least the first few lines) can be read using the DATE informat.

 

Also note that if you are using LIST MODE input there is no need to specify the width on your INFORMAT since SAS will ignore them anyway.  In list mode it adjusts the informat width to match the width of the data for that field. 

 

Also you almost NEVER want to add a decimal specification to an informat.  Do you really want any integer values divided by 10?

 

Also I like to use YYMMDD format to display dates to avoid confusion between locales that use MDY order and those that use DMY order.  Did you mean November 12th or the 10th of December?

 

data googlestat; 
  infile '/folders/myfolders/preprocessedgooglestatstab.txt'
     dlm='09'x dsd firstobs=2 truncover
  ;
  length DayofWeek $10 Date 8 Impressions 8 Clicks 8 Revenue 8;
  input DayofWeek Date :date. Impressions Clicks Revenue :comma.;
  format date yymmdd10.;
run; 

 

View solution in original post


All Replies
Highlighted
Solution
‎02-23-2018 05:45 PM
Super User
Super User
Posts: 8,074

Re: which informat I should use?

[ Edited ]

The main thing is to use LIST MODE input statement. So either remove the informats from the INPUT statement, or add : modifier in front of them.

 

You do not need to tell SAS to use an informat to read most values.  Your example has two values where it is useful, a date and number with embedded thousands separators.

 

Your date values (at least the first few lines) can be read using the DATE informat.

 

Also note that if you are using LIST MODE input there is no need to specify the width on your INFORMAT since SAS will ignore them anyway.  In list mode it adjusts the informat width to match the width of the data for that field. 

 

Also you almost NEVER want to add a decimal specification to an informat.  Do you really want any integer values divided by 10?

 

Also I like to use YYMMDD format to display dates to avoid confusion between locales that use MDY order and those that use DMY order.  Did you mean November 12th or the 10th of December?

 

data googlestat; 
  infile '/folders/myfolders/preprocessedgooglestatstab.txt'
     dlm='09'x dsd firstobs=2 truncover
  ;
  length DayofWeek $10 Date 8 Impressions 8 Clicks 8 Revenue 8;
  input DayofWeek Date :date. Impressions Clicks Revenue :comma.;
  format date yymmdd10.;
run; 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 201 views
  • 2 likes
  • 2 in conversation