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

Hi

 

Using SAS Enterprise Guide 7.1, is there any what that I can make SAS recognize data steps eg. in the context of text formatting?

That is, is there any way that I can make the word 'data' inside my macro definition below dark blue as in the data step outside the macro definition? And the same for the words 'set' and 'where' and so on?

 

I realize that macros are essentially just replacement of text, but I am wondering if it is possible.

 

Thank you in advance 🙂

 

data mydata;
	set sashelp.cars;
	where cylinders = 10;
run;

%macro make_dataset(inDS = );
	data mydata;
		set &inDS;
		where cylinders = 10;
	run;
%mend make_dataset;

 

Regards

 

EDIT: I noticed that the inserted code here does exactly what I want to do, but my Enterprise guide however does not. (See snip)

 

Udklip.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its not that I am not fond of macro, it is a very useful tool, its just that most of the time its either used as a replacement for knowledge of Base SAS, or cobbling together very messy code.  Probably what your experiencing with these "quite a few".  If its some sort of library of macros or set of them, then this is where SDLC should come in (and it is a good use for macro).  Design macros with functional design specs, testing, user manual etc.  Then the actual code itself is irrelevant.  Unfortunately most of the time this is either not done, or a small part is doen some time after development.

 

Anyhows, back to the question.  The editor recorgnises the "&" in that code triggering the code highlighting - it can do this anywhere as the & is fixed, so if you use that symbol followed by a non-numeric or missing character is assumes its a macro variable.  Maybe this code will illustrate why it can't highlight free text:

%macro somemacro ();
  data will go here
%mend;

data _null_;
  put "%somemacro";
run;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

No.  And the reason is that which you have given yourself.  Macro is nothing more that a text find/replace system, and as such takes the text within the macro and mend statements as plain text, resolves anything within the macro pre-processor, and then replaces that in the code text file and send to the compiler.  You can put anything you like in there, and until it passes through the macro pre-processor you will not know exactly what it will look like.  Use macro sparingly, and only when it adds value to the code and you will find this is not an issue as you will use Base SAS 99% of the time.

PeterClemmensen
Tourmaline | Level 20

Thank you for your answer. I am not fund of the macro laguage myself and I try to avoid it whenever I can. However I am in a situation where I have to use and maintain quite a few of them. It confuses me a bit though, that EG 7.1 can't do this when it can highligt character, macro variables and numbers though? 🙂

 

Udklip.PNG

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its not that I am not fond of macro, it is a very useful tool, its just that most of the time its either used as a replacement for knowledge of Base SAS, or cobbling together very messy code.  Probably what your experiencing with these "quite a few".  If its some sort of library of macros or set of them, then this is where SDLC should come in (and it is a good use for macro).  Design macros with functional design specs, testing, user manual etc.  Then the actual code itself is irrelevant.  Unfortunately most of the time this is either not done, or a small part is doen some time after development.

 

Anyhows, back to the question.  The editor recorgnises the "&" in that code triggering the code highlighting - it can do this anywhere as the & is fixed, so if you use that symbol followed by a non-numeric or missing character is assumes its a macro variable.  Maybe this code will illustrate why it can't highlight free text:

%macro somemacro ();
  data will go here
%mend;

data _null_;
  put "%somemacro";
run;
PeterClemmensen
Tourmaline | Level 20

This makes sense. Thank you very much @RW9.

 

Regards

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
  • 771 views
  • 1 like
  • 2 in conversation