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
I would fix the length-statement in the step creating the dataset. BUT why do you need to have the same length?
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
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.