1 / 42

Why Does SAS ® Say That? What Common DATA Step and Macro Messages Are Trying to Tell Y ou

Why Does SAS ® Say That? What Common DATA Step and Macro Messages Are Trying to Tell Y ou. Charley Mullin and Kevin Russell SAS Institute Inc., Cary, NC USA. Today You Will Learn to…. Better understand the SAS log Debug your code more easily Work more efficiently .

zita
Download Presentation

Why Does SAS ® Say That? What Common DATA Step and Macro Messages Are Trying to Tell Y ou

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Why Does SAS® Say That? What Common DATA Step and Macro Messages Are Trying to Tell You Charley Mullin and Kevin Russell SAS Institute Inc., Cary, NC USA

  2. Today You Will Learn to… • Better understand the SAS log • Debug your code more easily • Work more efficiently

  3. First, Let’s Discuss the DATA Step The benefits of DATA step: • Gives you the ability to read external files into SAS data sets • Enables you to manipulate data into a more usable form • Enables you combine data from various sources • And more…

  4. In the SAS Log, You Will Encounter: • Notes • Warnings • Errors

  5. Variables with Multiple Definitions ERROR: Variable VAR1 has been defined as both character and numeric. data two; input var1 var2; datalines; 3 4 ; run; data one; input var1 $ var2; datalines; 1 2 ; run; data three; merge one two; by var1 var2; run;

  6. Variables with Multiple Definitions (continued) ERROR: Variable VAR1 has been defined as both character and numeric. data one; set one(rename=(var1=temp)); var1=input(temp,??8.); drop temp; run; data two; set two(rename=(var1=temp)); var1=put(temp,8.); drop temp; run;

  7. Input to Concatenation Functions NOTE: Argument 1 to function CATS at line N column X is invalid.  NOTE: Further warning from this call to CATS will be suppressed. WARNING: In a call to the CATS function, the buffer allocated for the result was not long enough to contain the concatenation of all the arguments. The correct result would contain 1040 characters, but the actual result may either be truncated to 200 character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most argument that caused truncation. NOTE: Argument 1 to function CATS at line N column 6 is invalid.

  8. Input to Concatenation Functions (continued) data final; merge group1(rename=(results=r1)) group2(rename=(results=r2)) group3(rename=(results=r3)); results=cats(r1,r2,r3); run; data final; merge group1(rename=(results=r1)) group2(rename=(results=r2)) group3(rename=(results=r3)); length results $ 1040; results=cats(r1,r2,r3); run;

  9. Arguments to the Function SUBSTR • NOTE: Invalid second argument to function SUBSTR at line N column X. • NOTE: Invalid third argument to function SUBSTR at line N column X.

  10. Arguments to the Function SUBSTR (continued) In typical usage, the three arguments to the SUBSTR function are: • The name of the variable from which to extract characters • The position in the variable to start extracting characters • The number of characters to extract

  11. Arguments to the Function SUBSTR (continued) NOTE: Invalid second argument to function SUBSTR at line N column X. data lab_work; infile datalines truncover; input raw $char20.; machine=substr(strip(raw),1,4); test_id=substr(strip(raw),6,4); results=substr(strip(raw),11,4); datalines; 1234 5678 1234 5678 9012 ; run;

  12. Arguments to the Function SUBSTR (continued) NOTE: Invalid second argument to function SUBSTR at line N column X. data lab_work; infile datalines truncover; input raw $char20.; machine=substr(left(raw),1,4); test_id=substr(left(raw),6,4); results=substr(left(raw),11,4); datalines; 1234 5678 1234 5678 9012 ; run;

  13. Arguments to the Function SUBSTR (continued) NOTE: Invalid third argument to function SUBSTR at line N column X. data test; date=‘24/04/2012’; year=substr(date,7,10); run; data test; date=‘24/04/2012’; year=substr(date,7,4); run;

  14. Automatic Variable Type Conversions • NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). • NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).

  15. Automatic Variable Type Conversions (continued) NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column) data test; ssn=111223333; first_three=substr(ssn,1,3); run; The SAS System first_ Obs ssn three 1 111223333 proc print data=test; run;

  16. Automatic Variable Type Conversions (continued) NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column) The SAS System first_ Obs ssn three 1 111223333 111 data test; ssn=111223333; first_three=substr(put(ssn,z9.),1,3); run; proc print data=test; run;

  17. Uninitialized Variable NOTE: Variable FEMELE is uninitialized. data two; set one; if sex=1 then gender=Femele; run;

  18. Uninitialized Variable (continued) SAS Log: 3652 data two; 3653 set one; 3654 if sex=1 then gender=Femele; 3655 run; NOTE: Variable Femele is uninitialized.

  19. Uninitialized Variable (continued) Correct syntax: data two; set one; if sex=1 then gender=‘Female’; run;

  20. Using a Function Name As an Array Name NOTE: The array <name> has the same name as a SAS-supplied or user-defined function. Parentheses following this name are treated as array references and not function references.

  21. Using a Function Name As an Array Name(continued) SAS log: 43 data test; 44 array max(3) max1-max3 (80 90 70); NOTE: The array max has the same name as a SAS-supplied or user-defined function. Parentheses following this name are treated as array references and not function references. 45 max_value=max(of max(*)); ERROR: Too many array subscripts specified for array max. 46 run; NOTE: The SAS System stopped processing this step because of errors.

  22. Using a Function Name As an Array Name(continued) data test; array max(3) max1-max3 (80 90 70); max_value=max(of max(*)); run; data test; array maxx(3) max1-max3 (80 90 70); max_value=max(of maxx(*)); run;

  23. Now Let’s Discuss the Macro Facility The macro facility allows you to extend and customize your code and reduce the amount of text you must enter.

  24. When Using the Macro Facility, Use These System Options: • SYMBOLGEN • MPRINT • MLOGIC

  25. Masking Special Characters ERROR: Macro function %substr has too many arguments. The excess arguments will be ignored. %let x=a,b,c; %let y=%substr(&x,1,1); %put &=y; %let x=a,b,c; %let y=%substr(a,b,c,1,1); %put &=y;

  26. Masking Special Characters (continued) Complete error in the SAS log: 189 %let x=a,b,c; 190 %let y=%substr(&x,1,1); SYMBOLGEN: Macro variable X resolves to a,b,c ERROR: Macro function %SUBSTR has too many arguments. The excess arguments will be ignored. ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: b ERROR: Argument 2 to macro function %SUBSTR is not a number. ERROR: A character operand was found in the %EVAL function or %IFcondition where a numeric operand is required. The condition was: c ERROR: Argument 3 to macro function %SUBSTR is not a number. 191 %put &=y; &=y

  27. Masking Special Characters (continued) Corrected code: %let x=a,b,c; %let y=%substr(%bquote(&x),1,1); %put &=y;

  28. Autocall Macros Used As Macro Functions • %CMPRES and %QCMPRES • %COMPSTOR • %DATATYP • %KVERIFY • %LEFT and %QLEFT • %LOWCASE and %QLOWCASE • %TRIM and %QTRIM • %VERIFY

  29. Autocall Macros Used As Macro Functions (continued) Example that illustrates a problem: options mautosource sasautos=(‘c:\mymacs’); %let x=%str(abc ); %let y=%trim(&x);

  30. Autocall Macros Used As Macro Functions (continued) SAS log: 3 options mautosource sasautos=('c:\mymacs'); 4 %let x=%str(abc ); 5 %let y=%trim(&x); WARNING: Apparent invocation of macro TRIM notresolved.

  31. Autocall Macros Used As Macro Functions (continued) Correct setting for the SASAUTOS system option: options mautosource sasautos=(sasautos, 'c:\mymacs'); %let x=%str(abc ); %let y=%trim(&x);

  32. Using Macro Variables in Filenames ERROR: Physical file does not exist, c:\class2011csv. %let year=2011; proc import datafile="C:\class&year.csv" dbms=csv out=myclass replace; getnames=yes; run;

  33. Using Macro Variables in Filenames (continued) ERROR: Physical file does not exist, c:\class2011csv. datafile=“c:\class2011csv”;

  34. Using Macro Variables in Filenames (continued) ERROR: Physical file does not exist, c:\class2011csv. Here is the correct syntax: %let year=2011; proc import datafile=“C:\class&year..csv” dbms=csv out=myclass replace; getnames=yes; run;

  35. Referencing Stored Compiled Macros ERROR: A LOCK IS NOT AVAILABLE FOR LIBREF.SASMACR.CATALOG.

  36. Referencing Stored Compiled Macros (continued) ERROR: A lock is not available for MYMACS.SASMACR.CATALOG. libname mymacs ‘C:\macros’; options mstored sasmstore=mymacs; %macro test / store; <code>; %mend test; %test

  37. Referencing Stored Compiled Macros (continued) SAS log: NOTE: The SAS System was unable to open the macro library referenced by the SASMSTORE = libref MYMACS. ERROR: A lock is not available for MYMACS.SASMACR.CATALOG. ERROR: A dummy macro will be compiled.

  38. Referencing Stored Compiled Macros (continued)

  39. Invoking a Macro with Parameters Error: More positional parameters found than defined. %macro test(vals); %put &=vals; %mend test; %test(x,y,z)

  40. Invoking a Macro with Parameters (continued) SAS log: 19 %macro test(vals); 20 %put &=vals; 21 %mend test; 22 %test(x,y,z) MLOGIC(TEST): Beginning execution. MLOGIC(TEST): Parameter VALS has value x ERROR: More positional parameters found thandefined. MLOGIC(TEST): Ending execution.

  41. Invoking a Macro with Parameters (continued) Corrected code: %macro test(vals); %put &=vals; %mend test; %test(%str(x,y,z))

  42. Questions? Support@SAS.com (919) 677-8008 http://support.sas.com/techsup

More Related