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

Hello

Please see a code to create a macro variable.

How can we remove spaces in the macro variable   &No_words.?

data tbl1;
 set sashelp.cars;
numWords = countw(model, '');  
Run;



Proc SQL noprint;
select  max(numWords)  into   :No_words
 from tbl1;  
quit;
%put &No_words.;

 I know to do it in proc step but my question is how to do it in proc sql

 

data tbl1;
 set sashelp.cars  end=eof;
       retain numWords 0;           
       numWords = max(numWords , countw(model, ''));    
       /* for each line of text, how many words */
       if eof then call symputX('No_words',numWords);
Run;
%put &No_words.;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

Hi,

one solution would be to use the key word 'trimmed'

 

DATA tbl1;
   set sashelp.cars;
   numWords = countw(model, '');  
RUN;

PROC SQL noprint;
   SELECT  max(numWords) INTO :No_words TRIMMED
   FROM tbl1;  
QUIT;
%put &No_words.;
________________________

- Cheers -

View solution in original post

4 REPLIES 4
Oligolas
Barite | Level 11

Hi,

one solution would be to use the key word 'trimmed'

 

DATA tbl1;
   set sashelp.cars;
   numWords = countw(model, '');  
RUN;

PROC SQL noprint;
   SELECT  max(numWords) INTO :No_words TRIMMED
   FROM tbl1;  
QUIT;
%put &No_words.;
________________________

- Cheers -

ajs_rdg
Fluorite | Level 6

Thanks, that's useful.

 

 

Documentation here:


INTO Clause
Assigns values produced by PROC SQL to macro variables.
https://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n1y2jszlvs4hugn14nooftfrxhp3.htm&docse...
Leading and trailing blanks are not trimmed from values before they are stored in macro variables


not as informative as documentation here:


INTO Clause
Stores the value of one or more columns for use later in another PROC SQL query or SAS statement.
https://support.sas.com/documentation/cdl//en/sqlproc/69822/HTML/default/viewer.htm#p0hwg3z33gllron1...
https://support.sas.com/documentation/cdl//en/sqlproc/69822/HTML/default/viewer.htm#p0hwg3z33gllron1...
TRIMMED
trims the leading and trailing blanks from values that are stored in a single macro variable.

Tom
Super User Tom
Super User

Note there is a FEEDBACK button on that first link.  So I used it to send them your link to the page that does include the TRIMMED option.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9627 views
  • 12 likes
  • 5 in conversation