BookmarkSubscribeRSS Feed
JasonNC
Quartz | Level 8

I want to create value as shown below

Jan'16

Feb'16

 

The code i created

 

%let month=%sysfunc(month(%sysfunc(today())));
%put &month;
%let year=%sysfunc(year(%sysfunc(strip(%sysfunc(today())))));
%put &year;

 

proc format ;
value month 1='Jan'
2='Feb'
3='Mar'
4='Apr'
5='May'
6='Jun'
7='Jul'
8='Aug'
9='Sep'
10='Oct'
11='Nov'
12='Dec'

;
run;

 

Data _null_;
Year=put(&year,4.);
yy=Substr(Year,3,2);
mth=strip(put(&month.,month.));
mth_yy=strip(catx("'",mth,yy));
call symput('Mthyy',mth_yy);
run;

%put &Mthyy;

 

log

Aug'16;GOPTIONS NOACCESSIBLE;%LET _CLIENTTASKLABEL=;%LET _CLIENTPROJECTPATH=;%LET _CLIENTPROJECTNAME=;%LET _SASPROGRAMFILE=;;*'

 

It's showing the value but when i am trying to use the value to access the folder it's saying the folder length is 262 charachters long or some thing

 

When i tried removing the single quotation in the macro variable it's working fine.

 

Can any one look into this asap

4 REPLIES 4
Reeza
Super User

Please clarify and show how your using it and how it doesn't work there. 

You can use formats such as MONNAME3. And year2 to get the components. 

 

It sounds like you have folders that have a single quote in the file path?

Untested:

 

data _null_;

date=today();

call symputx('Mmthyy', catx("'", put(date, monname3.), put(date, year2.)));

run;

 

%put &mmthyy;

 


@JasonNC wrote:

I want to create value as shown below

Jan'16

Feb'16

 

The code i created

 

%let month=%sysfunc(month(%sysfunc(today())));
%put &month;
%let year=%sysfunc(year(%sysfunc(strip(%sysfunc(today())))));
%put &year;

 

proc format ;
value month 1='Jan'
2='Feb'
3='Mar'
4='Apr'
5='May'
6='Jun'
7='Jul'
8='Aug'
9='Sep'
10='Oct'
11='Nov'
12='Dec'

;
run;

 

Data _null_;
Year=put(&year,4.);
yy=Substr(Year,3,2);
mth=strip(put(&month.,month.));
mth_yy=strip(catx("'",mth,yy));
call symput('Mthyy',mth_yy);
run;

%put &Mthyy;

 

log

Aug'16;GOPTIONS NOACCESSIBLE;%LET _CLIENTTASKLABEL=;%LET _CLIENTPROJECTPATH=;%LET _CLIENTPROJECTNAME=;%LET _SASPROGRAMFILE=;;*'

 

It's showing the value but when i am trying to use the value to access the folder it's saying the folder length is 262 charachters long or some thing

 

When i tried removing the single quotation in the macro variable it's working fine.

 

Can any one look into this asap


 

Kurt_Bremser
Super User

If you actually have folders or filenames containing single quotes, use a LART on the one who created them in the first way.

Blanks, quotes and the like have no place in file or directory names, period.

 

Your problem comes from the fact that wherever you use your macro variable, a single quote is inserted into the program text (macro is just a text generator!), and what happens thereafter is the same as when you had entered that single quote manually. This also explains the funny layout of the log, as everything that EG does automatically is masked until the "magic line" with ;*';*";*/;quit;run; appears that finally terminates your virtual string; without the magic line your Workspace Server session would become unusable until you sent it a terminating single quote.

Your string does work if you enlcose it in double quotes:

proc format ;
value _month
  1='Jan'
  2='Feb'
  3='Mar'
  4='Apr'
  5='May'
  6='Jun'
  7='Jul'
  8='Aug'
  9='Sep'
  10='Oct'
  11='Nov'
  12='Dec'
;
run;

data _null_;
year = year(today());
month = month(today());
string = put(month,_month.) !! "'" !! substr(put(year,4.),3,2);
put string=;
call symput('Mthyy',trim(string));
run;

%put "&Mthyy";

I had to use _month for the format name, as SAS already has a format with the name month.

data_null__
Jade | Level 19

Try a PICTURE format, then you don't have to mess with all those functions and concatenation.

proc format;
   picture mmmxyy other='%3B''%y' (datatype=date);
   run;
   
data _null_;
   x = today();
   put x=mmmxyy.;
   run;
x=Aug'16

 

 

 

 

Tom
Super User Tom
Super User

Looks like you got the value into the macro variable.  Your problem is not taking care for how you use it becuase of the single quote.

 

When you use it in the actual filename it should not be an issue.  A statement like 

filename in "/mypath/Data for &mthyr.csv";

would work find since the unbalanced single quote will be inside of balanced double quotes.

 

If you want to view the value using %PUT you will need to either also add quotes.

%put "&mthyr";

Or add macro quoting.

%put %superq(mthyr);
%put %bquote(&mthyr);
%let mthyr=%superq(mthyr);
%put &mthyr;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 933 views
  • 2 likes
  • 5 in conversation