Using a macro variable containing special character build with "into :" keyword

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Using a macro variable containing special character build with "into :" keyword

[ Edited ]
data import;
	infile datalines;
	input id "var-1"n $ "var'g"n $ "var % of"n;
datalines;
1 d e 23
2 f g 34
3 g k 45
;;;;


proc contents data=import noprint varnum out=varlist ;

proc sql noprint;
	select name into :mylist separated by ' ' from varlist where type = 2;

proc freq data=import;
	tables &mylist.;
run;

The question is easy. How can i make this code works ? The problems are the special character inside the mylist macro variable.

 

thanks.


Accepted Solutions
Solution
‎01-02-2018 05:29 PM
Super Contributor
Posts: 320

Re: Using a macro variable containing special character build with "into :" keyword

Posted in reply to arjunascagnetto

You can use the NLITERAL function here.  I also simplify by using DICTIONARY.COLUMNS, but you can do the same in the PROC CONTENTS output.

 


proc sql;
	select nliteral(name)
      into :mylist separated by ' ' 
      from dictionary.columns
      where  memname='IMPORT' and type='char'
	;
quit;

View solution in original post


All Replies
Solution
‎01-02-2018 05:29 PM
Super Contributor
Posts: 320

Re: Using a macro variable containing special character build with "into :" keyword

Posted in reply to arjunascagnetto

You can use the NLITERAL function here.  I also simplify by using DICTIONARY.COLUMNS, but you can do the same in the PROC CONTENTS output.

 


proc sql;
	select nliteral(name)
      into :mylist separated by ' ' 
      from dictionary.columns
      where  memname='IMPORT' and type='char'
	;
quit;
Super User
Posts: 3,666

Re: Using a macro variable containing special character build with "into :" keyword

Posted in reply to arjunascagnetto

Why make life hard for yourself by defining variable names containing special characters? If there is no real business need for them then it is a lot easier just to use "standard" variable names. Remember you can define labels for SAS variables that contain special characters if they are required for reporting.

Occasional Contributor
Posts: 5

Re: Using a macro variable containing special character build with "into :" keyword

of course this is a simplificatin of a real problem OF COURSE!
Super User
Posts: 3,666

Re: Using a macro variable containing special character build with "into :" keyword

Posted in reply to arjunascagnetto

Perhaps if you explained the real problem, we could offer advice on that.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 272 views
  • 4 likes
  • 3 in conversation