BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DaniloTrindade
Fluorite | Level 6

Olá pessoal, alguém saberia me informar se há como debugar código no SAS Studio usando a plataforma OnDemand? Estou tentando escrever um código, mas só gera erro no log. Na pasta "CSV_FILES" tem dois arquivos simples que criei para testar: base_teste_202001 e base_teste_202012.

 

Estou tentando carregar uns arquivos de forma automática, onde cada arquivos se chama, respectivamente, base_teste_202001 até.. 202012. No curso "Programming I Essentials" não aborda esse assunto, mas estou tentando entender de forma autodidata.

 

Alguém saberia e poderia me ajudar nessa questão? Segue código e arquivos para fazer os mesmos testes que fiz e entender onde estou errando.

 

Desde já agradeço!

 

 

LIBNAME CSVFILE "FILEPATH/CSV_FILES";

%MACRO CSVFILE(MYFILE);
	%DO I = 1 %TO 12;
  
		PROC IMPORT DATAFILE="FILEPATH/CSV_FILES/&MYFILE..csv"
		            OUT=CSVFILE.&MYFILE REPLACE
		            DBMS=CSV;
			GETNAMES=YES;
		RUN;
  
		%IF &I < 10 %THEN %DO
			%CSVFILE(base_teste_2020&CATT("0", &I));
		%ELSE %DO
			%CSVFILE(base_teste_2020&I);
		%END;
	%END;
	
%MEND CSVFILE;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

SAS Log

426   %MACRO CSVFILE(MYFILE);
427     %DO I = 1 %TO 12;
428
429       PROC IMPORT DATAFILE="FILEPATH/CSV_FILES/&MYFILE..csv"
430                   OUT=CSVFILE.&MYFILE REPLACE
431                   DBMS=CSV;
432         GETNAMES=YES;
433       RUN;
434
435       %IF &I < 10 %THEN %DO
436         %CSVFILE(base_teste_2020&CATT("0", &I));
ERROR: An unexpected semicolon occurred in the %DO statement.
ERROR: A dummy macro will be compiled.
437       %ELSE %DO
ERROR: There is no matching %IF statement for the %ELSE.
438         %CSVFILE(base_teste_2020&I);
ERROR: An unexpected semicolon occurred in the %DO statement.
439       %END;
440     %END;
441
442   %MEND CSVFILE;

Use PUTN() to add leading zeros. Put the IMPORT step inside the %DO loop.

Use PUTN () para adicionar zeros à esquerda. Coloque a etapa IMPORT dentro do loop %DO.

%let path=FILEPATH/CSV_FILES;
LIBNAME CSVFILE "&path";

%macro csvfile(prefix);
%local month myfile;
%do month=1 %to 12 ;
  %let myfile=&prefix.%sysfunc(putn(&month,z2.));
* import &myfile ;
PROC IMPORT DATAFILE="&path/&MYFILE..csv"
            OUT=CSVFILE.&MYFILE REPLACE
            DBMS=CSV
;
	GETNAMES=YES;
RUN;
%end;
%mend csvfile;

%csvfile(base_teste_2020)

View solution in original post

4 REPLIES 4
OliveiraMiguelZ
Obsidian | Level 7
Seu código está gerando recursividade.

Tenta realocar o proc import pra parte onde você colocou pra chamar a macro e limpa o proc import lá de cima.

Geralmente, quando um erro não aparece no Log, significa que é um erro dentro de alguma macro, que o sistema não consegue entender. Você pode verificar o último erro que ocorreu procurando nas variáveis disponível pelo
%Put _ALL_;
OliveiraMiguelZ
Obsidian | Level 7
Além disso, faltam ; depois dos %DO
Tom
Super User Tom
Super User

SAS Log

426   %MACRO CSVFILE(MYFILE);
427     %DO I = 1 %TO 12;
428
429       PROC IMPORT DATAFILE="FILEPATH/CSV_FILES/&MYFILE..csv"
430                   OUT=CSVFILE.&MYFILE REPLACE
431                   DBMS=CSV;
432         GETNAMES=YES;
433       RUN;
434
435       %IF &I < 10 %THEN %DO
436         %CSVFILE(base_teste_2020&CATT("0", &I));
ERROR: An unexpected semicolon occurred in the %DO statement.
ERROR: A dummy macro will be compiled.
437       %ELSE %DO
ERROR: There is no matching %IF statement for the %ELSE.
438         %CSVFILE(base_teste_2020&I);
ERROR: An unexpected semicolon occurred in the %DO statement.
439       %END;
440     %END;
441
442   %MEND CSVFILE;

Use PUTN() to add leading zeros. Put the IMPORT step inside the %DO loop.

Use PUTN () para adicionar zeros à esquerda. Coloque a etapa IMPORT dentro do loop %DO.

%let path=FILEPATH/CSV_FILES;
LIBNAME CSVFILE "&path";

%macro csvfile(prefix);
%local month myfile;
%do month=1 %to 12 ;
  %let myfile=&prefix.%sysfunc(putn(&month,z2.));
* import &myfile ;
PROC IMPORT DATAFILE="&path/&MYFILE..csv"
            OUT=CSVFILE.&MYFILE REPLACE
            DBMS=CSV
;
	GETNAMES=YES;
RUN;
%end;
%mend csvfile;

%csvfile(base_teste_2020)
DaniloTrindade
Fluorite | Level 6

This solution worked. Thank you very much. Now I go to study this code.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Discussion stats
  • 4 replies
  • 1183 views
  • 18 likes
  • 3 in conversation