Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SAS, How do you find whitespace in a macro variable?

Tags:

sas

How do you find the position of whitespace in a macro variable? For example,

%let someString = the quick brown fox;
%let nextSpace = %index(&someString,' ');

The above code doesn't work. &nextSpace will be equal to 0. However, I suspect there should be a way to find the position of a space in a macro variable.

Many thanks!

like image 328
Deets McGeets Avatar asked Jun 02 '14 01:06

Deets McGeets


People also ask

How do I check if a macro variable is blank?

Re: check if macro variable is null Here's the simple way: %if %length(&a)=0 %then %do; Good luck.

How do I find the value of a macro variable in SAS?

You can also use a %PUT Macro Statement to view available macro variables. %PUT provides several options that enable you to view individual categories of macro variables. The system option SYMBOLGEN displays the resolution of macro variables.

How do I use a macro variable in SAS?

After a macro variable is created, you typically use the variable by referencing it with an ampersand preceding its name (&variable-name), which is called a macro variable reference. These references perform symbolic substitutions when they resolve to their value. You can use these references anywhere in a SAS program.


1 Answers

%let nextSpace = %index(&someString,%str( ));

Quotes don't work in macro variables, of course. You need to use macro quoting, such as %str in this case.

like image 133
Joe Avatar answered Sep 30 '22 23:09

Joe