BookmarkSubscribeRSS Feed
acordes
Rhodochrosite | Level 12

When I load a xlsx file through the data import wizard into a cas table I run into problems with the variable name conventions every time I use this table in a data step. 

The error log is like:

82 data public.test;
83 set public.FSVBALA_2112_NEW;
ERROR: The value 'IMPORTE CUOTA MENSUAL CLENTE A FIN DE MES'n is not a valid SAS name.
84 run;

Even a renaming statement does not work aborting the data step without finishing. 

I circumvent this by wrapping the data step into a cas datastep.runcode. 

then it works. 

 

PROC CAS;
dataStep.runCode result=r status=rc / code='/* BEGIN data step with the output table data */
data "FSVBALA_2112_NEW2" (caslib="public" promote="no");
/* Set the input set */
set "FSVBALA_2112_NEW" (caslib="public" );
array temp date_baja date_dev_contable date_dev_fianza date_devolucion date_fin_serv_inicial date_fin_serv_real 
date_finiquito date_firma_contable date_listado date_marca_recompra 
date_matricula date_pago_conc date_paso_a_vhe date_prefiniquito date_ult_paso_taller;
do over temp;
if (2002 le year (temp) le  2030) then call missing (heart);
end;
rename ''IMPORTE CUOTA MENSUAL CLENTE A FIN DE MES''n=''IMPO CUOTA MENS CLi A FIN DE MES''n 
''Importe devengado acumulado periódico VR''n=''Imp devengado acum peri VR''n
''CLASE ELEMENTO CONCESIONARIO VENDEDOR''n =''CLASE ELEM CONC VENDEDOR''n
''IMPORTE TOTAL CUOTA ALQUILER + SERVICIOS''n=''IMP TOT CUOTA ALQ + SERV''n 
''Importe de la subvención a Valor residual''n =''Imp de la sub a VR''n
''Cuota total con IVA sin subvención''n=''Cuota tot con IVA sin sub''n 
''Cuota total con IVA con subvención''n=''Cuota tot con IVA con sub''n
''Código modalidad producto renting''n=''Cod mod producto renting''n
''Código producto Renting Seguro suplido (S) No suplido ( )''n=''Cod prod Rt Seg suplido''n;
drop ''Al inicio : modalidad de seguro como suplido''n ''Importe seguro pagado proveedor (sin extornos)''n
''Importe devengado acumulado periódico''n ''Asistencia en viaje   Suplido (S)  No suplido ( )''n
''Asistencia en viaje   Suplido (S)  No suplido ( )_1''n ''Fecha Asistencia cambio seguro a no suplido''n
''Fecha Asistencia cambio seguro a no suplido_1''n ''Fecha Asistencia cambio seguro a no suplido_2''n
''Importe Asistencia pagado proveedor (sin extornos)''n  ''Extornos cobrados a proveedor asistencia''n  ''Importe devengado acumulado periódico_1''n  
''Importe degengado aperiódico (cancel anticipadas)''n  ''Vehículo reemplazo en viaje   Suplido (S)  No suplido ( )''n  
''Fecha Vehículo reemplazo cambio seguro a no suplido''n  ''Fecha Vehículo reemplazo cambio seguro a no suplido_1''n  
''Fecha Vehículo reemplazo cambio seguro a no suplido_2''n  ''Importe Vehículo reemplazo pagado proveedor (sin extornos)''n  
  ''Día Devolución Contable del coche''n  ''Mes Devolución Contable del coche''n 
 ''Año Devolución Contable del coche''n  ''Importe pendiente facturar mantenimiento''n  ''Importe pendiente facturar neumáticos''n  
 ''Código de cliente Norma centro de coste''n  ''Importe anual impuesto municipal cobrado cliente''n 
 ''Importe anual impuesto municipal a pagar a proveedor''n  ''Importe anual Asistencia viaje pagar a proveedor''n  ''Importe anual Vehículo de reemplazo''n 
 ''Importe total de mantenimiento a pagar a  Proveedor''n  ''Importe total de neumáticos a pagar a  Proveedor''n  ''Importe mensual cobrado costes financieros''n 
 ''Importe mensual cobrado de gestión de multas''n  ''Importe mensual pagado de gestión de multas''n  ''Mg. Comercial Asistencia en viaje''n 
 ''Mg. Comercial Vehículo de reemplazo''n  ''Importe exceso km. hasta 200.000 km.''n  ''Importe exceso km. desde 200.000 km.''n  
''IMPORTE CLIENTE PENALIZACIÓN CANCELACIÓN ANTICPADA''n  ''IMPORTE PAGADO POR EL CLIENTE MANTENIMIENTO EN FINIQUITO O CANCEL ANTIC''n  
''IMPORTE PAGADO VALOR RESIDUAL EN FINIQUITO O CANCEL ANTIC''n    ''Importe ruedas pagado a proveedor''n  
''Km. último paso por taller o captura kilometraje''n  ''Importe 1ª cuota sin IVA servicios incluidos''n  
''Importe total cuota Estándar sin IVA servicios incluidos''n  ''Importe ultima cuota sin IVA error igual que cuota estandar''n  
''Importe total cliente Provisión combustible''n  ''Importe total cancelación anticipada''n  ''Matrícula del vehículo que se renueva''n 
 ''Cuota mensual de mantenimiento sin neumáticos''n  ''Cuota mensual de Asistencia en viaje''n  ''Cuota mensual de vehículo de reemplazo''n  
''Importe días usados (S/N)/ COBRADOS''n  ''Operación renting servicio preentrega''n   
''Ingreso reconocido por mantenimientos''n  ''Ingreso reconcocido por neumaticos''n  ''Importe total cliente Support Mantenimiento''n  
''Importe total cliente aportación Empleador''n  ''Importe pagado vehículo reemplazo fuera cobertura''n 
 ''Importe total indemnización por siniestro total''n  ''Importe pagado vehículo reemplazo fuera cobertura extras''n  ''Importe previsto de la subvención''n 
  ''Importe mensual gestión de flota''n
;
run;';
QUIT;

To get the variable names that cause such error I cannot use proc contents as it derails for the same naming issue.

So I use columninfo action but I get an NOTE 49-169: The meaning of an identifier error note when I use the macro variable of the variable names inside double single quote. 

 

%let tab=FSVBALA_2112_NEW;
%let casy=public;
%let varlist="";

proc cas;
/*     session vf_session; */
  
    action columninfo result=r /table={name="&tab.", caslib="&casy."};
    
    empty = 0;
    if (r.columnInfo.nrows <= 0) then do;
      empty = 1;
      rc = symput("emptyTable", (string)empty);
    end;
    else do;
      columns = "";
      	do i = 1 to r.columninfo.nrows;
			if length(strip(r["columninfo"][i,1])) > 32 THEN do;
         		symput("col", "''"||tranwrd(r[1,i].column, "'","''")||"''n ");
         		columns = columns||" "|| symget("col");
			end;
      end;
      symput("varlist", substrn(columns,2,length(columns)-1));
    end;
run;

quit;

%put &varlist;

The eror note is like:

49 49 49
49
49
110! ''Importe días usados (S/N)/ COBRADOS''n ''Operación renting servicio preentrega''n ''Importe de la subvención a Valor
NOTE: Line generated by the macro variable "VARLIST".
110 residual''n ''Ingreso reconocido por mantenimientos''n ''Ingreso reconcocido por neumaticos''n ''Importe total cliente
-- -- --
--
--
49 49 49
49
49
110! Support Mantenimiento''n ''Importe total cliente aportación Empleador''n ''Importe pagado vehículo reemplazo fuera
110! cobertura''n
NOTE: Line generated by the macro variable "VARLIST".

 

How to avoid this? Because my workaround is to create a pipe instead of the second single quote and later replace it. 

 

'|Importe total cliente aportación Empleador''n

 

Furthermore the %put &varlist does not obey the line integrity, I mean the string can span over two lines which I'd like to avoid. Like:

'|Operación renting servicio preentrega''n '|Importe de la subvención a Valor residual''n '|Ingreso reconocido por
mantenimientos''n '|Ingreso reconcocido por neumaticos''n '|Importe total cliente Support Mantenimiento''n '|Importe total

  

 

1 REPLY 1
SASKiwi
PROC Star

What about doing your Excel import on a Viya workspace server that supports SAS 9 functionality? Then you could use the VALIDVARNAME = V7 system option to convert the column names automatically to valid SAS ones before loading into a CAS library. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 255 views
  • 0 likes
  • 2 in conversation