To check whether there is a variable with more than 200 characters in all datasets in SAS, you can use the following code:

/* Step 1: Get a list of all datasets */
proc sql noprint;
   select memname into :ds_list separated by ' '
   from dictionary.tables
   where libname='WORK'; /* Change the libname if necessary */
quit;

/* Step 2: Loop through each dataset and check variable lengths */
%macro check_variable_length;
   %do i = 1 %to %sysfunc(countw(&ds_list));
      %let ds = %scan(&ds_list, &i);

      data _null_;
         set &ds;
         length var_list $200.;
         retain var_list;

         array _allvars[*] _character_;
         do i = 1 to dim(_allvars);
            if length(_allvars[i]) > 200 then
               var_list = catx(" ", var_list, vname(_allvars[i]));
         end;
         if _n_ = 1 then
            call symputx('var_list', var_list);
      run;

      /* Step 3: Output the results */
      %if &var_list ne %then %do;
         %put The following variables in dataset &ds have more than 200 characters: &var_list;
      %end;
   %end;
%mend;

/* Step 4: Run the macro */
%check_variable_length;

This code will check each dataset in the WORK library and output the variables that have more than 200 characters. If you have datasets in a different library, you can modify the libname in the SQL query accordingly

SAS code check whether there is variable which has more than 200 characters in all dataset

原文地址: https://www.cveoy.top/t/topic/iQFj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录