BookmarkSubscribeRSS Feed
Gick
Pyrite | Level 9

Hello,

I have several character variables of length 3, 5 , 13 or 90. I would like to define a  length of 70 for all the variables.

Since I have several character variables (minus 120), I cannot change the length of each variable one by one.

 

I want to automate this data step, can someone help me please?

 

Thank you
Gick

3 REPLIES 3
andreas_lds
Jade | Level 19

I would fix the length-statement in the step creating the dataset. BUT why do you need to have the same length?

 

Gick
Pyrite | Level 9

Because I want to apply a program that retrieves the name of the variable_name of the modality. For example male_sex. But it turns out that some variables have length 3, so doing so cuts off the name of the new modality.

For example the sex variable has a length of 7, by applying my program I find sex_ho.
Image that I have a variable of length 3 but its name has 5 characters, with my program it will not take its modalities.

For example: sales of yes/no modalities, the result will be sal instead of sales_oui.

Reason for which, I wish to define a maximum length of 70 like that, all my program will give me the result which I seek.

Waiting for your contribution, thank you.

Gick

andreas_lds
Jade | Level 19

Sorry, but i can't follow your explanation. I would be easier, if you could post data in usable form and  show what you want to achieve using that example.

 

Using sashelp.class:

/* Clone sashelp.class */
data work.class;
   set sashelp.class;
run;

/* Get char vars and use call execute to apply the fix */
data strings;
   set sashelp.vcolumn(where= (Libname = 'WORK' and MemName = 'CLASS' and upcase(Type) = 'CHAR')) end=jobDone;
   
   if _n_ = 1 then do;
      call execute('proc sql noprint;');
      call execute('alter table work.class modify');
   end;
   
   call execute(catx(' ', Name, 'char(70)', ifc(not jobDone, ',', '')));
   
   if jobDone then do;
      call execute('; quit;');
   end;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1156 views
  • 2 likes
  • 2 in conversation