BookmarkSubscribeRSS Feed
UrvishShah
Fluorite | Level 6

Hi

i've the data which contains 100 obs

data test;

input num;

cards;

1

2

3

4

5

up to

100

;

nw i want to assign the names to the different values by using the Proc Format

Proc Format;

    Values Name

        1 = 'name1'

        2 = 'name2'

        3 = 'name3'

            up to

      100 = 'name100';

SO it is taking the more time

My question is that without HARD CODING hw can i assign the name to the different values ?

11 REPLIES 11
art297
Opal | Level 21

Not sure I understand.  Is the following what you want?

data test;

  do num=1 to 100;

    output;

  end;

run;

proc sql noprint;

  create table for_format as

    select "nums" as fmtname,

           num as start,

           catt("name",num) as label

      from test

  ;

quit;

proc format cntlin=for_format;

run;

UrvishShah
Fluorite | Level 6

Thanks

But suppose i want to assign the names which are not coming in series in that case what is the solution ?

Reeza
Super User

So how are you assigning the names? Where do they come from?

You might want to google CNTLIN option with proc format and see if that helps.

art297
Opal | Level 21

Provide an example of what you mean, including the expected input and result.  Unless, that is, you just need something like:

proc sql noprint;

  create table for_format as

    select distinct "nums" as fmtname,

           num as start,

           catt("name",num) as label

      from test

        order by num

  ;

quit;

proc format cntlin=for_format;

run;

UrvishShah
Fluorite | Level 6

Proc Format;

   Value Names

         1 = Mike

         2 = Spike

         3 = Kite

                

up to

         100 = Pink;

run;

Nw if i wan to assign these names to the different values then what to do ?

Because Do Loop can work only if we have seq. data but if i wan to assign the different names then what is the solution ?

art297
Opal | Level 21

You still don't provide enough info.  The names have to come from somewhere.

Please provide an example of your data, whether that be one file, or more than one file.  Otherwise, everyone on the forum can only guess what your real situation is.

Which brings to mind another question.  What are you really trying to accomplish?

UrvishShah
Fluorite | Level 6

data test;

input num;

cards;

1

2

3

4

up to

100

;

proc format;

  values Names

     1 = 'Kite'

     2 = 'Mikes'

  up to

   100 = 'pink';

if i go this way then it will take more time to code

I just want to ask is there any shortcuts in Proc Format so that i can assign above these names to the variable num ?

And if i  use Do loop then it will work only if i have sequentianal data like name1 name2 name3 name4 and so on

art297
Opal | Level 21

Either you or I didn't understand my questions and what you are trying to do..

You can automate almost anything but, hopefully, it would result in something meaningful!

Is there a relationship between names and num?

Do you have a file with the names?

Does it make any difference which name gets assigned to which num?

FriedEgg
SAS Employee

data foo;

input label $ start @@;

retain fmtname 'myfmt';

cards;

Yael 1 Hillary 2 Mechelle 3 Henry 4 Melinda 5 Josiah 6 Hyatt 7 Kalia 8 Phelan 9 Amal 10

Keith 11  Alea 12 Grady 13 Kaitlin 14 Damian 15 Berk 16 Timothy 17 Noelle 18 Carter 19 Libby 20

Kuame 21 Shafira 22 Philip 23 Uta 24 Hadassah 25 Cora 26 Holly 27 Kermit 28 Maia 29 Howard 30

Gail 31 Linus 32  Roth 33 Zephania 34 Abdul 35 Jescie 36  Jordan 37 Idola 38 Zelenia 39  Darrel 40

Jamalia 41 Kathleen 42  Dillon 43 Rudyard 44 Alice 45 Julie 46 Ulysses 47 Vivian 48 Colin 49 Baker 50

Kennan 51 Quynn 52 Velma 53 Ella 54 Nero 55 Erica 56 Karen 57 Blaze 58 Shaeleigh 59 Cadman 60

Katelyn 61 Chaney 62 Patricia 63 Gannon 64 Cedric 65 Paul 66 Ruby 67 Merrill 68 Carolyn 69 Roanna 70

Trevor 71 Madison 72  Fredericka 73 Chandler 74  Isadora 75 Graiden 76  Morgan 77 Grant 78 Erica 79 Tashya 80

Ivory 81 September 82 Micah 83 Harding 84 Brooke 85 Hadley 86 Mufutau 87  Martena 88 Jescie 89 Keelie 90

Raymond 91 Abbot 92 Noel 93 Kellie 94 Gareth 95 Tallulah 96 Dustin 97 Cara 98 Kirsten 99 Isadora 100

;

run;

proc format library=work cntlin=foo; run;

data bar;

call streaminit( 12345 );

do i=1 to 100;

  num=abs(mod(int(rand('NORMAL')*10**3),100))+1;

  name=put(num,myfmt.);

  output;

end;

drop i;

run;

Ksharp
Super User

Are these names('Kite' 'Mikes') files or tables?

If they are tables, you can merge it into test table ,then use proc format cntlin=.

Ksharp

Peter_C
Rhodochrosite | Level 12

Urvish

is it a picture format that you want ?

- so NNN appears as NameNNN

??

proc format ;

picture nameit other= '0000001'( prefix='Name' )  ;

run;

%put

%sysfunc( putn(   3, nameit ))

%sysfunc( putn(  23, nameit ))

%sysfunc( putn( 123, nameit )) ;

In my log I get

Name3      Name23     Name123

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1526 views
  • 3 likes
  • 6 in conversation