BookmarkSubscribeRSS Feed
jc3992
Pyrite | Level 9

Should I use "Trim" or "Compress"?

 

The Q is:

    1. Modify the code used to create the profits report so the spaces after the Q’s in the title “Based on data from Q 1 2011 to Q 4 2013” disappear; that is, so the new title reads “Based on data from Q1 2011 to Q4 2013”. Of course, you need to do this so the results are based on the data in the file, even if the data changes, so you need to extract the information as was done in Week6 to put it in the title. My code is as below:
      %let dirdata=/folders/myfolders;
      libname perm "&dirdata";
      
      data perm.profits;
      set profits "&dirdata";
      proc print data=perm.profits;
      run;
      
      data profitsA;
      	retain sumP;
      	set perm.profits end=eof;
      	if _n_=1 then do;
      		call symput('y1',year);
      		call symput('q1',qtr);
      	end;
      	sumP+profit;
      	VARVAL=COMPRESS('q1',S);
      	if eof then do;
      		call symput('y2',year);
      		call symput('q2',qtr);
      		VARVAL=COMPRESS('q2',S);
      		call symput('sumProfit',sumP);
      		sumPNice=put(sumP,dollar7.);
      		call symput('sumProfitNice',sumPNice);
      		thisDay=put(date(),worddate18.);
      		call symput('tdDate1',thisDay);
      	end;
      run;
      
      title "Based on data from Q&q1 &y1 to Q&q2 &y2:";
      title2 "Total profits are &sumProfitNice.. Great work, everyone!";
      title3 "Report produced &tdDate1 (%sysfunc(date(),mmddyy8.)).";
      
      proc print data=profitsA;
      title;
      run;
      LOG:
       1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
       2          TITLE;
       3          FOOTNOTE;
       4          OPTIONS LOCALE=en_US DFLANG=LOCALE;
       NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
       5          DATA _NULL_;
       6          RUN;
       7          OPTIONS VALIDVARNAME=V7;
       8          OPTIONS VALIDMEMNAME=COMPAT;
       9          FILENAME _HTMLOUT TEMP;
       10         FILENAME _RTFOUT TEMP ENCODING='UTF-8';
       11         FILENAME _PDFOUT TEMP;
       12         FILENAME _GSFNAME TEMP;
       13         FILENAME _DATAOUT TEMP;
       14         %LET SYSCC=0;
       15         %LET _CLIENTAPP='SAS Studio';
       16         %LET _CLIENTAPPABREV=Studio;
       17         %LET _CLIENTAPPVERSION=3.7;
       18         %LET _CLIENTVERSION=3.7;
       19         %LET _CLIENTMODE=basic;
       20         %LET _SASSERVERNAME=%BQUOTE(localhost);
       21         %LET _SASHOSTNAME=%BQUOTE(localhost);
       22         %LET _SASPROGRAMFILEHOST=%BQUOTE(localhost);
       23         %LET _CLIENTUSERID=%BQUOTE(sasdemo);
       24         %LET _CLIENTUSERNAME=%BQUOTE(sasdemo);
       25         %LET CLIENTMACHINE=%BQUOTE(10.0.2.2);
       26         %LET _CLIENTMACHINE=%BQUOTE(10.0.2.2);
       27         %let SASWORKLOCATION="%sysfunc(getoption(work))/";
       28         FILENAME _CWD '.';
       29         DATA _NULL_;
       30         CALL SYMPUT('_SASWORKINGDIR',PATHNAME('_CWD'));
       31         RUN;
       32         FILENAME _CWD;
       33         
       34         %LET _SASPROGRAMFILE = %NRQUOTE(%NRSTR(/folders/myfolders/Programs/Week_6/ChenJenli_jc3992_Assignment5.sas));
       35         %LET _BASEURL = %BQUOTE(http://localhost:10080/SASStudio/);
       36         %LET _EXECENV=SASStudio;
       
                  ______________________________________________________________________________________________________________________
                  49
       
       
       NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
                    between a quoted string and the succeeding identifier is recommended.
       
       37         DATA _NULL_;
       38         CALL
       38       ! SYMPUT("GRAPHINIT"
                                   _
                                   49
       38       ! ,"");
       39         CALL
       39       ! SYMPUT("GRAPHTERM"
                                   _
                                   49
       39       ! ,"");
       NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
                    between a quoted string and the succeeding identifier is recommended.
       
       40         RC=TSLVL('GEOCODE','N');
       41         _ERROR_=0;
       42         IF (RC^=' ') THEN DO;
       43         CALL SYMPUT("GRAPHINIT","GOPTIONS RESET=ALL GSFNAME=_GSFNAME;");
                                        ___                                    ________________
                                        49                                     49
       44         CALL SYMPUT("GRAPHTERM","GOPTIONS NOACCESSIBLE;");
                                        ___                      ___________________________________
                                        49                       49
       NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
                    between a quoted string and the succeeding identifier is recommended.
       
       45         END;
       46         RUN;
       47         DATA _NULL_;
       48         RC=SYSPROD("PRODNUM002"
                                        _
                                        49
       48       ! );
       NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
                    between a quoted string and the succeeding identifier is recommended.
       
       49         IF (RC^=1) THEN DO;
       50         CALL
       50       ! SYMPUT("GRAPHINIT"
                                   _
                                   49
       50       ! ,"");
       NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
                    between a quoted string and the succeeding identifier is recommended.
       
       51         CALL SYMPUT("GRAPHTERM","");
       52         END;
       53         RUN;
       54         %LET _DATAOUT_MIME_TYPE=;
       55         %LET _DATAOUT_NAME=;
       56         %LET _DATAOUT_TABLE=;
       57         %LET _DATAOUT_URL=;
       58         %SYMDEL _DATAOUT_MIME_TYPE _DATAOUT_NAME _DATAOUT_URL _DATAOUT_TABLE;
       59         %LET _SASWS_ = %BQUOTE(/folders/myfolders);
       60         %LET _SASWSTEMP_=%BQUOTE(/folders/myfolders/.sasstudio/.images/09859bac-b10d-4435-a5a2-dd2a3120cdc0);
       61         ODS LISTING CLOSE;
       62         ODS AUTONAVIGATE OFF;
       63         ODS GRAPHICS ON;
       64         ODS HTML5 (ID=WEB) DEVICE=PNG GPATH="&_SASWSTEMP_" ENCODING=utf8  FILE=_HTMLOUT (TITLE='Results:
       64       ! ChenJenli_jc3992_Assignment5.sas') STYLE=Htmlblue OPTIONS(BITMAP_MODE='INLINE' OUTLINE='ON' SVG_MODE='INLINE'
       64       ! CSS_PREFIX='.ods_09859bac-b10d-4435-a5a2-dd2a3120cdc0' BODY_ID='div_09859bac-b10d-4435-a5a2-dd2a3120cdc0' );
       NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
       65         ODS RTF (ID=WEB) STYLE=Rtf FILE=_RTFOUT sasdate;
       66         ODS PDF (ID=WEB) STYLE=Pearl FILE=_PDFOUT;
       67         &GRAPHINIT;
       68         OPTIONS FIRSTOBS=1;
       69         OPTIONS OBS=MAX;
       70         OPTIONS DTRESET DATE NUMBER NOTES;
       71         OPTIONS NOTES STIMER SOURCE NOSYNTAXCHECK;
       72         
       73         %let dirdata=/folders/myfolders;
       74         libname perm "&dirdata";
       75         
       76         data perm.profits;
       77         set profits "&dirdata";
       78         proc print data=perm.profits;
       79         run;
       80         
       81         data profitsA;
       82         retain sumP;
       83         set perm.profits end=eof;
       84         if _n_=1 then do;
       85         call symput('y1',year);
       86         call symput('q1',qtr);
       87         end;
       88         sumP+profit;
       89         VARVAL=COMPRESS('q1',S);
       90         if eof then do;
       91         call symput('y2',year);
       92         call symput('q2',qtr);
       NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
       93         VARVAL=COMPRESS('q2',S);
       94         call symput('sumProfit',sumP);
       95         sumPNice=put(sumP,dollar7.);
       96         call symput('sumProfitNice',sumPNice);
       97         thisDay=put(date(),worddate18.);
       98         call symput('tdDate1',thisDay);
       99         end;
       100        run;
       101        
       102        title "Based on data from Q&q1 &y1 to Q&q2 &y2:";
       103        title2 "Total profits are &sumProfitNice.. Great work, everyone!"
                                                                                  __________
                                                                                  49
       103      ! ;
       NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space 
                    between a quoted string and the succeeding identifier is recommended.
       
       104        title3 "Report produced &tdDate1 (%sysfunc(date(),mmddyy8.)).";
       105        
       106        proc print data=profitsA;
       107        title;
       108        run;
       109        
       110        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
       111        ODS HTML CLOSE;
       112        &GRAPHTERM; ;*';*";*/;RUN;QUIT;
       113        QUIT;RUN;
       114        ODS HTML5 (ID=WEB) CLOSE;
       115        
       116        ODS RTF (ID=WEB) CLOSE;
       117        ODS PDF (ID=WEB) CLOSE;
       118        FILENAME _GSFNAME;
       119        DATA _NULL_;
       120        RUN;
       121        OPTIONS VALIDMEMNAME=COMPAT;
       122        OPTIONS NOTES STIMER SOURCE SYNTAXCHECK;
       123        
       User: sasdemo
      No output at all.Any ideas?
4 REPLIES 4
Astounding
PROC Star

You are not ready for this.

 

You need to know what a SET statement looks like.

 

You need to know what the UPCASE function does.

 

You need to know what an IF statement does.

 

Do not venture anywhere near macro language until you can solve your earlier problem.  I'm not trying to be harsh here, just realistic as to where your time is best spent.

jc3992
Pyrite | Level 9

Thanks!

But that was what we were asked to.

Thanks for all the suggestions.

But really for programming, who can say they are really prepared for all?

learn and practice. that is just how it goes.

I also got other courses but need to get the wrk down.

I am not doing nothing but ask.

I spent three days for this.

But who can control what questions they are going to assign?

 

ballardw
Super User

Did your instructor teach you to use?

libname perm "&dirdata";

data perm.profits;
set profits "&dirdata";

 

If so I would suggest finding a class with another instructor.

 

If not, take better notes in class.

 

Did you have a program that provided the correct output without using any macro variables or other macro code? If not then you are not ready to use any macros. The macro language creates code. If you do not know what the code should look like then it is too soon to attempt macro coding. If you have code that worked start with that and change one piece with a macro variable at a time to duplicate the code that ran successfully.

 

For example if I have code like this that runs successfully:

libname perm '/folders/myfolders';

proc print data=perm.profits;
run;

I suggest

 

%let dirdata =/folders/myfolders/ ;
libname perm "dirdata.";

proc print data=perm.profits;
run;

So far I think you have submitted example code with 5 different formats for the SET statement and while one of them would work it was a poor choice. I am not sure that have read the log for most your attempts as you post code that will generate errors.

 

s_lassen
Meteorite | Level 14

Nothing much wrong with your code, despite the voices claiming that you are an imbecile.

 

But it is true that you need to correct the SET statement. Or maybe drop the whole datastep to create perm.profits?

 

The problem in your log seems to be that before you submitted the code shown, you submitted some other code with unmatched quotes in it. Try saving your code, and restart SAS, then it will probably run.

 

To get rid of the trailing spaces in your macro variables, use the SYMPUTX function instead of SYMPUT, it's as simple as that! 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1298 views
  • 0 likes
  • 4 in conversation