BookmarkSubscribeRSS Feed
Miah
Obsidian | Level 7

I am trying to change the format of column Gross, which contains values like $50,319,942. I wish to make my program treat this variable as numeric. 

 

This is my code but it is not displaying the values of this column. 

 

DATA movies;
INFILE "/folders/myfolders/GrossDays.txt" DLM='09'x MISSOVER FIRSTOBS=2 DSD;
INPUT Title :$100. Date :ANYDTDTE20. Gross Theaters Distributor $;
RUN;

PROC PRINT DATA=movies;
FORMAT Date DATE9.;
RUN;

PROC PRINT DATA = music;
FORMAT Date DATE. ;
FORMAT Gross 10. ;
RUN;

DATA movies;
SET movies;
TheaterAvg = (Gross/Theaters);
RUN;

PROC PRINT DATA = movies;
RUN;

 

3 REPLIES 3
art297
Opal | Level 21

You just need to add an informat when inputting gross. e.g.:

 

DATA movies;
  INFILE "/folders/myfolders/GrossDays.txt" DLM='09'x MISSOVER FIRSTOBS=2 DSD;
  INPUT Title :$100. Date :ANYDTDTE20. Gross dollar12. Theaters Distributor $;
RUN;

Art, CEO, AnalystFinder.com

Tom
Super User Tom
Super User

Make sure to include the : prefix so that it uses list mode input since the source file is delimited and not fixed columns.

  INPUT Title :$100. Date :ANYDTDTE. Gross :dollar. Theaters Distributor :$20.;

You don't need widths on your INFORMATs when using list mode, SAS will ignore them.

But you do want to include the width in the $xx. informats since that way SAS can use the width the make a better guess at what length you want the character variables to use.

art297
Opal | Level 21

@Tom: It works, in this case, with or without the : for gross as long as one includes the dollar. informat

@Miah: One additional problem with your code:

PROC PRINT DATA = music;
	FORMAT Date DATE. ;
	FORMAT Gross 10. ;
RUN;

Shouldn't that have been data = movies ?

 

Art, CEO, AnalystFinder.com

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 1519 views
  • 0 likes
  • 3 in conversation