DATA Step, Macro, Functions and more

proc format for numeric value

Reply
Frequent Contributor
Posts: 76

proc format for numeric value

I have a dataset like

STUDENTNAME  DIVISION

A                        firstdiv

B                        secdiv

C                        thirdiv

D                        firstdiv

F                        thirdiv

I have to create a format like

proc format $division;

value 'firstdiv' =1

        'secdiv'=2

        'thirdiv'=3

        'all'= '1','2','3','all';

Kindly help me how to create format

Regards,

Ashwini

Frequent Contributor
Posts: 76

proc format for numeric value

Please ignore the above dataset .The dataset is like

Studentname  division

A                    1

B                    2

c                    3

D                   2

F                   3

I have to create a format like

proc format $division;

value 'firstdiv' =1

        'secdiv'=2

        'thirdiv'=3

        'all'= '1','2','3','all';

Kindly help me how to create format

Regards,

Ashwini

Respected Advisor
Posts: 3,892

Re: proc format for numeric value

Some code like below and as documented under http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473491.htm could do.

data have;

  infile datalines dsd;

  input Studentname $  division;

datalines;

A,1

B,2

c,3

D,2

F,3

;

run;

data ctrl / view=ctrl;

  retain fmtname 'division' type 'c';

  set have(rename=(Studentname=Start)) end=last;

  label=put(Division,1.);

  output;

if last then do;

    hlo='O';

  label='?';

    output;

end;

run;

proc format lib=work cntlin=ctrl;

run;

data _null_;

  do StudentName='A','B','X','F';

    put 'Student ' StudentName 'is in Division ' StudentName $division.;

  end;

run;

PROC Star
Posts: 7,363

Re: proc format for numeric value

I'm confused!  What are you trying to do?  Your proc format is slightly reversed from your data .. the data values should be on the left and their meanings on the right, the format name should come after the word value, from your data and subject line you are trying to create a numeric format but you specified a character format, and it appears like you actually want a multilabel format.  Are you looking to accomplish something like?:

data have;

  input Studentname $ division score;

  cards;

A  1 13

B  2 9

c  3 6

D  2 12

F  3 18

;

proc format;

value  division (multilabel)

  1='firstdiv'

  2='secdiv'

  3='thirdiv'

  1,2,3='all'

  ;

run;

proc means data=have mean nonobs;

   class  division /mlf order=fmt;

   var score;

   format division division.;

run;

Super User
Posts: 9,681

Re: proc format for numeric value

May be you are looking:

proc format $division;

value 'firstdiv' ='1'

        'secdiv'='2'

        'thirdiv'='3'

        'all'= '1 , 2, 3, all';

Ask a Question
Discussion stats
  • 4 replies
  • 143 views
  • 0 likes
  • 4 in conversation