BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
user40
Calcite | Level 5

Is it wrong to write like this in SAS code that you want t to be a string in macro? 

%macro hentami(t,data,aar); 

data kuhr&aar.;
set kuhr.kuhr_&aar.;
rename pasientlopenummer =lopenummer;
run;

data "&t"kuhr&aar.;
merge &data (in=a) kuhr&aar.;
if a by lopenummer;

uke =round((differansedager -inn_refdager0)7,1);
tjeneste=sum(fastlege,legevakt,spesialist,psykolog);
if uke ge 0 and uke le 52 then output;
run;
%mend;

%hentami_kuhr(ami,ami_index,2008);


I got an error message when I write "&t"kuhr&aar. in macro %hentami_kuhr(t,data,aar) there t is a text, data is a dataset and aar is year (like 2008). How can I rewrite this macro code? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

Try modifying it as follows

 

data &t.kuhr&aar.;

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

Try modifying it as follows

 

data &t.kuhr&aar.;

user40
Calcite | Level 5
Thanks. It works. Then we cannot have special character in some macro like this &t._kuhr&aar.; ?
japelin
Rhodochrosite | Level 12

use %str or %nrstr for special charactor.

 

for example

%Macro Mtest(val);
  data sample;
    a="&val";
  run;
  proc print;run;
%Mend;

%Mtest(xxx,yyy)/* error */

%Mtest(%str(xxx,yyy))

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 403 views
  • 0 likes
  • 2 in conversation