Hello,
I am using a csv to generate variable lists in macros so I can run code through the rows of the csv.
When I run the code below I get a syntax error on all the references to &&event_num_&i.. It's weird because the macro seems to be resolving correctly. The log shows the correct values (in the screenshot the event_num = 5), but there is this extra space which causes the syntax error (see screenshot).
I don't know where the extra spaces are coming from, but you can certainly use %PUT statements at each step of the macro creation process to see where these extra spaces are coming from.
So for example
%put ********&event_type1************;
let's you see in the log if there are spaces before or after &event_type1.
You have gone though a lot of effort to create macro variables &event_type1 &event_type2 etc. as well as &likert1 &likert2 and many other macro variables. You can simplify the code by
proc sql noprint;
select event_type into :event_type1- from a;
quit;
which creates macro variables &Event_type1 &event_type2 ... &Event_typeN in a very compact piece of code.
Please turn on macro debugging options by running this command
options mprint;
Run the macro again. Show us the ENTIRE log down to the first error by copying the log as text (not as screen capture) and then pasting it into the window that appears when you click on the </> icon.
560 ******************************************* 561 ** NHWC RCQI Dashboard Input Creator 562 *******************************************; 563 options mprint; 564 565 *** Set up input/output destinations; 566 libname inputse "S:\projects\Workforce_Institute\5. RCQI\1. Phase One\7. Stakeholder 566! Engagements\SAS Datasets\Test"; NOTE: Libref INPUTSE was successfully assigned as follows: Engine: V9 Physical Name: S:\projects\Workforce_Institute\5. RCQI\1. Phase One\7. Stakeholder Engagements\SAS Datasets\Test 567 libname inputhc "S:\projects\Workforce_Institute\5. RCQI\1. Phase One\7. Stakeholder 567! Engagements\SAS Datasets\Test"; NOTE: Libref INPUTHC refers to the same physical library as INPUTSE. NOTE: Libref INPUTHC was successfully assigned as follows: Engine: V9 Physical Name: S:\projects\Workforce_Institute\5. RCQI\1. Phase One\7. Stakeholder Engagements\SAS Datasets\Test 568 libname inputttl "S:\projects\Workforce_Institute\5. RCQI\1. Phase One\7. Stakeholder 568! Engagements\SAS Datasets\Test"; NOTE: Libref INPUTTTL refers to the same physical library as INPUTHC. NOTE: Libref INPUTTTL was successfully assigned as follows: Engine: V9 Physical Name: S:\projects\Workforce_Institute\5. RCQI\1. Phase One\7. Stakeholder Engagements\SAS Datasets\Test 569 libname inputws "S:\projects\Workforce_Institute\5. RCQI\1. Phase One\8. Workshops\SAS Datasets"; NOTE: Libref INPUTWS was successfully assigned as follows: Engine: V9 Physical Name: S:\projects\Workforce_Institute\5. RCQI\1. Phase One\8. Workshops\SAS Datasets 570 libname inputot "S:\projects\Workforce_Institute\5. RCQI\1. Phase One\9. OT Events\SAS Datasets"; NOTE: Libref INPUTOT was successfully assigned as follows: Engine: V9 Physical Name: S:\projects\Workforce_Institute\5. RCQI\1. Phase One\9. OT Events\SAS Datasets 571 572 %let filepath="S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\Input Files\Phase 572! One\DashboardInput_(%sysfunc(today(),mmddyyd10.)).xlsx"; 573 %put &=filepath; FILEPATH="S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\Input Files\Phase One\DashboardInput_(09-19-2024).xlsx" 574 575 %let setup="S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\DashboardInputFile.csv"; 576 577 578 proc format; 579 value good 580 1 = 'Very poor' 581 2 = 'Poor' 582 3 = 'Average' 583 4 = 'Good' 584 5 = 'Very good'; NOTE: Format GOOD is already on the library WORK.FORMATS. NOTE: Format GOOD has been output. 585 586 value agree 587 1 = 'Strongly disagree' 588 2 = 'Disagree' 589 3 = 'Neither agree nor disagree' 590 4 = 'Agree' 591 5 = 'Strongly agree'; NOTE: Format AGREE is already on the library WORK.FORMATS. NOTE: Format AGREE has been output. 592 593 value duration 594 1 = 'Far too short' 595 2 = 'Slightly too short' 596 3 = 'Perfect length' 597 4 = 'Slightly too long' 598 5 = 'Far too long'; NOTE: Format DURATION is already on the library WORK.FORMATS. NOTE: Format DURATION has been output. 599 600 value future 601 1 = 'Very unlikely' 602 2 = 'Unlikely' 603 3 = 'Neutral' 604 4 = 'Likely' 605 5 = 'Very likely'; NOTE: Format FUTURE is already on the library WORK.FORMATS. NOTE: Format FUTURE has been output. 606 run; NOTE: PROCEDURE FORMAT used (Total process time): real time 0.02 seconds cpu time 0.03 seconds 607 608 *make table shells; 609 610 data role_shell; 611 length role $37.; 612 infile datalines dlm='|'; 613 input role $ sort; 614 datalines; NOTE: The data set WORK.ROLE_SHELL has 7 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 622 ; 623 run; 624 625 data org_shell; 626 length org $40.; 627 infile datalines dlm = '|'; 628 input org $ sort; 629 datalines; NOTE: The data set WORK.ORG_SHELL has 6 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 636 ; 637 run; 638 639 data hptp_shell; 640 length hptp $12.; 641 input hptp $ sort; 642 datalines; NOTE: The data set WORK.HPTP_SHELL has 3 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 646 ; 647 run; 648 649 650 data duration_shell; 651 length duration $18.; 652 infile datalines dlm='|'; 653 input duration $ sort; 654 datalines; NOTE: The data set WORK.DURATION_SHELL has 5 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 660 ; 661 run; 662 663 data good_shell; 664 length value $10; 665 infile datalines dlm='|'; 666 input value $ sort; 667 datalines; NOTE: The data set WORK.GOOD_SHELL has 5 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 673 ; 674 run; 675 676 data agree_shell; 677 length value $26; 678 infile datalines dlm='|'; 679 input value $ sort; 680 datalines; NOTE: The data set WORK.AGREE_SHELL has 5 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 686 ; 687 run; 688 689 data likely_shell; 690 length value $26; 691 infile datalines dlm='|'; 692 input value $ sort; 693 datalines; NOTE: The data set WORK.LIKELY_SHELL has 5 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 699 ; 700 run; 701 702 ******************************************** 703 Step 1: Read in input file; 704 *******************************************; 705 706 proc import datafile = &setup. 707 dbms = csv 708 out = setup 709 replace; 710 guessingrows=max; 711 run; 712 /********************************************************************** 713 * PRODUCT: SAS 714 * VERSION: 9.4 715 * CREATOR: External File Interface 716 * DATE: 19SEP24 717 * DESC: Generated SAS Datastep Code 718 * TEMPLATE SOURCE: (None Specified.) 719 ***********************************************************************/ 720 data WORK.SETUP ; 721 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */ 722 infile 'S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\DashboardInputFile.csv' 722! delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ; 723 informat event_type $2. ; 724 informat event_num best32. ; 725 informat rcqi_1 $9. ; 726 informat rcqi_2 $12. ; 727 informat rcqi_3 $10. ; 728 informat rcqi_4 $6. ; 729 informat rcqi_5 $2. ; 730 informat rcqi_6 $2. ; 731 informat rcqi_7 $1. ; 732 informat likert_1 $5. ; 733 informat likert_2 $4. ; 734 informat likert_3 $4. ; 735 informat likert_4 $4. ; 736 informat likert_5 $5. ; 737 informat likert_6 $5. ; 738 informat likert_7 $1. ; 739 informat oe_1 $9. ; 740 informat oe_2 $7. ; 741 informat oe_3 $11. ; 742 informat oe_4 $11. ; 743 informat oe_5 $8. ; 744 informat oe_6 $3. ; 745 informat oe_7 $1. ; 746 format event_type $2. ; 747 format event_num best12. ; 748 format rcqi_1 $9. ; 749 format rcqi_2 $12. ; 750 format rcqi_3 $10. ; 751 format rcqi_4 $6. ; 752 format rcqi_5 $2. ; 753 format rcqi_6 $2. ; 754 format rcqi_7 $1. ; 755 format likert_1 $5. ; 756 format likert_2 $4. ; 757 format likert_3 $4. ; 758 format likert_4 $4. ; 759 format likert_5 $5. ; 760 format likert_6 $5. ; 761 format likert_7 $1. ; 762 format oe_1 $9. ; 763 format oe_2 $7. ; 764 format oe_3 $11. ; 765 format oe_4 $11. ; 766 format oe_5 $8. ; 767 format oe_6 $3. ; 768 format oe_7 $1. ; 769 input 770 event_type $ 771 event_num 772 rcqi_1 $ 773 rcqi_2 $ 774 rcqi_3 $ 775 rcqi_4 $ 776 rcqi_5 $ 777 rcqi_6 $ 778 rcqi_7 $ 779 likert_1 $ 780 likert_2 $ 781 likert_3 $ 782 likert_4 $ 783 likert_5 $ 784 likert_6 $ 785 likert_7 $ 786 oe_1 $ 787 oe_2 $ 788 oe_3 $ 789 oe_4 $ 790 oe_5 $ 791 oe_6 $ 792 oe_7 $ 793 ; 794 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */ 795 run; NOTE: The infile 'S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\DashboardInputFile.csv' is: Filename=S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\DashboardInputFile.csv, RECFM=V,LRECL=32767,File Size (bytes)=997, Last Modified=19Sep2024:13:41:42, Create Time=19Sep2024:12:43:46 NOTE: 8 records were read from the infile 'S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\DashboardInputFile.csv'. The minimum record length was 78. The maximum record length was 119. NOTE: The data set WORK.SETUP has 8 observations and 23 variables. NOTE: DATA statement used (Total process time): real time 0.07 seconds cpu time 0.07 seconds 8 rows created in WORK.SETUP from S:\projects\Workforce_Institute\5. RCQI\0. Dashboard\DashboardInputFile.csv. NOTE: WORK.SETUP data set was successfully created. NOTE: The data set WORK.SETUP has 8 observations and 23 variables. NOTE: PROCEDURE IMPORT used (Total process time): real time 0.27 seconds cpu time 0.25 seconds 796 797 ************************************************************************************ 798 STEP 2a: Create macro lists of variables from the input excel. Macro will iterate 799 through these lists to produce outputs. 800 ***********************************************************************************; 801 802 proc sql noprint; 803 create table macros as 804 select event_type 805 ,event_num 806 ,rcqi_1 807 ,rcqi_2 808 ,rcqi_3 809 ,rcqi_4 810 ,rcqi_5 811 ,rcqi_6 812 ,rcqi_7 813 ,likert_1 814 ,likert_2 815 ,likert_3 816 ,likert_4 817 ,likert_5 818 ,likert_6 819 ,likert_7 820 ,oe_1 821 ,oe_2 822 ,oe_3 823 ,oe_4 824 ,oe_5 825 ,oe_6 826 ,oe_7 827 from setup 828 order by event_type, event_num 829 ; NOTE: Table WORK.MACROS created, with 8 rows and 23 columns. 830 831 /*Create a macro that holds a list of the column values from the input csv. In step 2b, we number 831! each value so the do loop 832 can run through each row of the csv using their numbered suffix. */ 833 select event_type into: event_type separated by " " 834 from setup; 835 select event_num into: event_num separated by " " 836 from setup; 837 select rcqi_1 into: rcqi_1 separated by " " 838 from setup; 839 select rcqi_2 into: rcqi_2 separated by " " 840 from setup; 841 select rcqi_3 into: rcqi_3 separated by " " 842 from setup; 843 select rcqi_4 into: rcqi_4 separated by " " 844 from setup; 845 select rcqi_5 into: rcqi_5 separated by " " 846 from setup; 847 select rcqi_6 into: rcqi_6 separated by " " 848 from setup; 849 select rcqi_7 into: rcqi_7 separated by " " 850 from setup; 851 select likert_1 into: likert_1 separated by " " 852 from setup; 853 select likert_2 into: likert_2 separated by " " 854 from setup; 855 select likert_3 into: likert_3 separated by " " 856 from setup; 857 select likert_4 into: likert_4 separated by " " 858 from setup; 859 select likert_5 into: likert_5 separated by " " 860 from setup; 861 select likert_6 into: likert_6 separated by " " 862 from setup; 863 select likert_7 into: likert_7 separated by " " 864 from setup; 865 select oe_1 into: oe_1 separated by " " 866 from setup; 867 select oe_2 into: oe_2 separated by " " 868 from setup; 869 select oe_3 into: oe_3 separated by " " 870 from setup; 871 select oe_4 into: oe_4 separated by " " 872 from setup; 873 select oe_5 into: oe_5 separated by " " 874 from setup; 875 select oe_6 into: oe_6 separated by " " 876 from setup; 877 select oe_7 into: oe_7 separated by " " 878 from setup; 879 880 *create macro that identifies the number of each type of event; 881 select count(event_type) into: max_se 882 from setup 883 where event_type='se'; 884 select count(event_type) into: max_ws 885 from setup 886 where event_type='ws'; 887 *create macro that identifies the last row in format csv to use as end of do loop in step 5; 888 select count(event_type) into: max 889 from setup; 890 891 quit; NOTE: PROCEDURE SQL used (Total process time): real time 0.09 seconds cpu time 0.09 seconds 892 893 run; 894 895 ******************************************************************************* 896 ** STEP 2b: Use the macro list created in step 2a to create numbered macros that 897 will allow us to iterate through each row of the input csv 898 (e.g., event_type_1 = se, rcqi_1 = Q7, etc. 899 ******************************************************************************; 900 901 data _null_; 902 set setup; 903 call symput(strip(cats("event_type_",_N_)),event_type); 904 call symput(strip(cats("event_num_",_N_)),event_num); 905 call symput(strip(cats("rcqi_1_",_N_)),rcqi_1); 906 call symput(strip(cats("rcqi_2_",_N_)),rcqi_2); 907 call symput(strip(cats("rcqi_3_",_N_)),rcqi_3); 908 call symput(strip(cats("rcqi_4_",_N_)),rcqi_4); 909 call symput(strip(cats("rcqi_5_",_N_)),rcqi_5); 910 call symput(strip(cats("rcqi_6_",_N_)),rcqi_6); 911 call symput(strip(cats("rcqi_7_",_N_)),rcqi_7); 912 call symput(strip(cats("likert_1_",_N_)),likert_1); 913 call symput(strip(cats("likert_2_",_N_)),likert_2); 914 call symput(strip(cats("likert_3_",_N_)),likert_3); 915 call symput(strip(cats("likert_4_",_N_)),likert_4); 916 call symput(strip(cats("likert_5_",_N_)),likert_5); 917 call symput(strip(cats("likert_6_",_N_)),likert_6); 918 call symput(strip(cats("likert_7_",_N_)),likert_7); 919 call symput(strip(cats("oe_1_",_N_)),oe_1); 920 call symput(strip(cats("oe_2_",_N_)),oe_2); 921 call symput(strip(cats("oe_3_",_N_)),oe_3); 922 call symput(strip(cats("oe_4_",_N_)),oe_4); 923 call symput(strip(cats("oe_5_",_N_)),oe_5); 924 call symput(strip(cats("oe_6_",_N_)),oe_6); 925 call symput(strip(cats("oe_7_",_N_)),oe_7); 926 927 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 904:47 NOTE: There were 8 observations read from the data set WORK.SETUP. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 928 929 ************************************************************************* 930 STEP 3: Do processing code using macro that will run for each row of the 931 input csv. 932 *************************************************************************; 933 934 935 %macro dashboard; 936 937 %do i=1 %to &max.; 938 939 proc sql noprint; 940 create table &&event_type_&i.._&&event_num_&i.._complete as 941 select "Completed RCQI" as cat, count(*) as N_&&event_num_&i.. 942 from input&&event_type_&i...&&event_type_&i.._&&event_num_&i.; 943 quit; 944 945 %end; 946 947 %mend dashboard; 948 949 %dashboard; MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_1". 1 se_ 1_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_1". 1 N_ 1 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_1". 1 inputse.se_ 1 - 22 76 MPRINT(DASHBOARD): create table se_ 1_complete as select "Completed RCQI" as cat, count(*) as N_ 1 from 1; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_2". 1 se_ 2_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_2". 1 N_ 2 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_2". 1 inputse.se_ 2 - 22 76 MPRINT(DASHBOARD): create table se_ 2_complete as select "Completed RCQI" as cat, count(*) as N_ 2 from 2; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.03 seconds MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_3". 1 se_ 3_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_3". 1 N_ 3 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_3". 1 inputse.se_ 3 - 22 76 MPRINT(DASHBOARD): create table se_ 3_complete as select "Completed RCQI" as cat, count(*) as N_ 3 from 3; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_4". 1 ws_ 1_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_4". 1 N_ 1 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_4". 1 inputws.ws_ 1 - 22 76 MPRINT(DASHBOARD): create table ws_ 1_complete as select "Completed RCQI" as cat, count(*) as N_ 1 from 1; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_5". 1 ws_ 2_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_5". 1 N_ 2 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_5". 1 inputws.ws_ 2 - 22 76 MPRINT(DASHBOARD): create table ws_ 2_complete as select "Completed RCQI" as cat, count(*) as N_ 2 from 2; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_6". 1 ws_ 3_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_6". 1 N_ 3 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_6". 1 inputws.ws_ 3 - 22 76 MPRINT(DASHBOARD): create table ws_ 3_complete as select "Completed RCQI" as cat, count(*) as N_ 3 from 3; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.02 seconds cpu time 0.01 seconds MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_7". 1 ws_ 4_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_7". 1 N_ 4 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_7". 1 inputws.ws_ 4 - 22 76 MPRINT(DASHBOARD): create table ws_ 4_complete as select "Completed RCQI" as cat, count(*) as N_ 4 from 4; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.00 seconds MPRINT(DASHBOARD): proc sql noprint; NOTE: Line generated by the macro variable "EVENT_NUM_8". 1 ws_ 5_complete - 22 200 NOTE 138-205: Line generated by the macro variable "EVENT_NUM_8". 1 N_ 5 - 22 ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE. ERROR 200-322: The symbol is not recognized and will be ignored. ERROR 22-322: Syntax error, expecting one of the following: ',', LEN, LENGTH. NOTE: Line generated by the macro variable "EVENT_NUM_8". 1 inputws.ws_ 5 - 22 76 MPRINT(DASHBOARD): create table ws_ 5_complete as select "Completed RCQI" as cat, count(*) as N_ 5 from 5; ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE. ERROR 76-322: Syntax error, statement will be ignored. MPRINT(DASHBOARD): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 950 951 %put &event_num_1; 1
I don't know where the extra spaces are coming from, but you can certainly use %PUT statements at each step of the macro creation process to see where these extra spaces are coming from.
So for example
%put ********&event_type1************;
let's you see in the log if there are spaces before or after &event_type1.
You have gone though a lot of effort to create macro variables &event_type1 &event_type2 etc. as well as &likert1 &likert2 and many other macro variables. You can simplify the code by
proc sql noprint;
select event_type into :event_type1- from a;
quit;
which creates macro variables &Event_type1 &event_type2 ... &Event_typeN in a very compact piece of code.
Ahh, I didn't realize I should include the asterisks. I removed the space by using symputx instead of symput. Thanks so much!
Also thanks for the tip on the numbered variables.
Pretty much any time you are doing a conversion from numeric to text, which is what the macro language is, text, you need to consider how SAS does that. If you don't explicitly control the conversion, such as with PUT and a format and possibly an alignment indicator, you get a generic routing that uses a BEST12. format, resulting in leading spaces if your value uses fewer digits.
I can't come close to remembering how many times I may have used trim(left(<somevariable>)) when building macro variables. Before Call SymputX was added to the statements.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.