BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arjunascagnetto
Fluorite | Level 6
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.

1 ACCEPTED SOLUTION

Accepted Solutions
snoopy369
Barite | Level 11

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

4 REPLIES 4
snoopy369
Barite | Level 11

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;
SASKiwi
PROC Star

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.

arjunascagnetto
Fluorite | Level 6
of course this is a simplificatin of a real problem OF COURSE!
SASKiwi
PROC Star

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 652 views
  • 4 likes
  • 3 in conversation