Help using Base SAS procedures

Format procedure

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Format procedure

Hi ,

   On running the format procedure I get and Error saying : " You are trying to use the numeric format SURVIVED with the character variable Survived in data set TITANIC.TRAIN."

Here is my code :

proc format;

value survived 1='Survived'

               0='Died'

     ;

  run;

ods graphics on;

proc freq data=titanic.train;

tables survived sex Pclass

survived*sex survived*pclass/

plots(only)=freqplot(scale=percent);

format survived survived.;

run;

When I change the "Survived" column to numeric datatype it works. How do I apply the format procedure to a character datatype column.?


Accepted Solutions
Solution
‎03-06-2014 06:13 PM
Super User
Posts: 19,855

Re: Format procedure

Posted in reply to MinalMurkhande

format survived $survived.;

View solution in original post


All Replies
Super User
Posts: 19,855

Re: Format procedure

Posted in reply to MinalMurkhande

Make a character format:

proc format;

value $ survived '1'='Survived'

              '0'='Died'

     ;

  run;

New Contributor
Posts: 3

Re: Format procedure

Hi Reeza,

Thank you for your reply.

I did try this option too but it still gives the same error .

Here is the excerpt from the log :

NOTE: Format $SURVIVED is already on the library WORK.FORMATS.

NOTE: Format $SURVIVED has been output.

29         run;

NOTE: PROCEDURE FORMAT used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

     

30         ods graphics on;

31         proc freq data=titanic.train;

32         tables survived sex Pclass

33         survived*sex survived*pclass/

34         plots(only)=freqplot(scale=percent);

35         format survived survived.;

ERROR: You are trying to use the numeric format SURVIVED with the character variable Survived in data set TITANIC.TRAIN.

36         run;

NOTE: The SAS System stopped processing this step because of errors.

Solution
‎03-06-2014 06:13 PM
Super User
Posts: 19,855

Re: Format procedure

Posted in reply to MinalMurkhande

format survived $survived.;

New Contributor
Posts: 3

Re: Format procedure

Thank you.. ! Got it Smiley Happy

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 2238 views
  • 0 likes
  • 2 in conversation