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

I am using enterprise guide 7.1 and sas 9.4.

I am trying to name datasets based on the type of information in them, mainly the group that they belong to. 5 day 30 day 60 day etc. When it gets to the naming part, the datasets show up in the output data section, but if you try to open them they are not there.  Any help is appreciated.  Thank you for your time.

 

%macro tock (seg,dset);

	data quick;
		format rpc_pct percent8.2;
		set finished;

		if segment eq &seg;
		rpc_pct = contact/attempt;
	RUN;

	proc sort data= quick;
		by descending rpc_pct;
	RUN;

	data quick;
		format rpc_rank 8.;
		set quick;

		if first.rpc_pct then
			rpc_rank= 0;
		rpc_rank + 1;
	RUN;

	proc sort data= quick;
		by descending cev;
	RUN;

	data quick2;
		format cev_rank 8. overall_rank 8.2;
		set quick;

		if first.cev then
			cev_rank =0;
		cev_rank +1;
		overall_rank=((0.8*cev_rank)+(.2*rpc_rank));
		group = missing(overall_rank);
	RUN;

	proc sort data= quick2;
		by group overall_rank;
	RUN;

	proc rank data=quick2 out=finalquick groups=4;
		var overall_rank;
		ranks tier;
	RUN;

	data finalquick;
		retain primekey agency segment tenure employeecode employeename attempt contact promise kept

			PromiseRate KeptRate CEV avgpay colldollars mean_cev std_cev rpc_pct rpc_rank

			cev_rank overall_rank tier;
		set finalquick;

		if tier = 3 then
			tier =4;
		else if tier = 2 then
			tier=3;
		else if tier = 1 then
			tier=2;
		else if tier = 0 then
			tier=1;
		keep primekey agency segment tenure employeecode employeename attempt contact promise kept

			PromiseRate KeptRate CEV avgpay colldollars mean_cev std_cev rpc_pct rpc_rank

			cev_rank overall_rank tier;
	RUN;

ISSUE:

	data _&dset.;
		set finalquick;
	RUN;

%mend;

%tock('5-Day','fiveday');
%tock('30-Day','thirtyday');

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

By putting quotes around the value you passed to the macro you confused SAS into thinking you meant to create two datasets.

 

See this example:

237   data _'First';
238    set sashelp.class;
239   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK._ has 19 observations and 5 variables.
NOTE: The data set First has 19 observations and 5 variables.

So it made one dataset named WORK._ and it made the other dataset in the current working directory of the process that is running the SAS code since the quoted physical name did not include any other directory information.

 

To the macro processor quotes are just part of the value.  Remove them in your call.

%macro tock (seg,dset);
...
if segment eq &seg;
...
data _&dset.;
...
%mend;

%tock('5-Day',fiveday);

Note that the value of SEG needs the quotes because the quotes are important in the SAS code that the macro is generating.  SAS needs the quotes to be able to distinguish between a string constant and a variable name or number.  The macro processor does not need quotes for this. To the macro processor everything is just text. It only needs to look for & or % triggers to see if it needs to process the strings.

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

By putting quotes around the value you passed to the macro you confused SAS into thinking you meant to create two datasets.

 

See this example:

237   data _'First';
238    set sashelp.class;
239   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK._ has 19 observations and 5 variables.
NOTE: The data set First has 19 observations and 5 variables.

So it made one dataset named WORK._ and it made the other dataset in the current working directory of the process that is running the SAS code since the quoted physical name did not include any other directory information.

 

To the macro processor quotes are just part of the value.  Remove them in your call.

%macro tock (seg,dset);
...
if segment eq &seg;
...
data _&dset.;
...
%mend;

%tock('5-Day',fiveday);

Note that the value of SEG needs the quotes because the quotes are important in the SAS code that the macro is generating.  SAS needs the quotes to be able to distinguish between a string constant and a variable name or number.  The macro processor does not need quotes for this. To the macro processor everything is just text. It only needs to look for & or % triggers to see if it needs to process the strings.

 

Reeza
Super User
I don't see any particular issues with your code, besides where you've added the ISSUE note. Does the log indicate any error? What happens if you try to run a proc contents on the data set? Or use it in a future step?

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 896 views
  • 3 likes
  • 3 in conversation