DATA Step, Macro, Functions and more

SAS Macro issue

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

SAS Macro issue

Hello Friends

I am trying to run the following code, but I am not error message as  Variable SALESDATE not found in data set WORK.FLOWERSALES.

%LET flowertype = Ginger;
data flowersales;
input customerID $4. @6 SalesDate mmddyy10. @17 Variety $9. quantity 3.;
IF Variety = "&flowertype";
datalines;
240W 02-07-2008 Ginger 120
240W 02-07-2008 Protea 180
356W 02-08-2008 Heliconia 60
356W 02-08-2008 Anthurium 300
188R 02-11-2008 Ginger 24
188R 02-11-2008 Anthurium 24
240W 02-12-2008 Heliconia 48
240W 02-12-2008 Protea 48
356W 02-12-2008 Ginger 240
;
run;
proc print data = flowersales;
format SalesDate WORDDATE18.;
TITLE "Sales of &flowertype";
run;

 

is there any wrong in the code?

Your help is highly appreciated.

Thanks


Accepted Solutions
Solution
‎09-29-2016 08:53 PM
Super User
Posts: 5,516

Re: SAS Macro issue

Posted in reply to sas_td2016

There's a minor issue with your code, but not one that would generate the result you are describing.  Did you read the portion of the log that describes the results of the DATA step?  That would be the most important part.

 

The minor issue is that the informat $9. might read extra characters, including part of the QUANTITY value.  The solution would be to add this statement before the INPUT statement:

 

length variety $ 9;

 

Then the portion of the INPUT statement that reads VARIETY would become:

 

input ... @17 variety $ quantity;

 

My suspicion is that your DATA step contains an error, and an earlier version of FlowerSales is being used (one that does not contain SalesDate).  But you'll have to read the log to be able to tell.

View solution in original post


All Replies
Solution
‎09-29-2016 08:53 PM
Super User
Posts: 5,516

Re: SAS Macro issue

Posted in reply to sas_td2016

There's a minor issue with your code, but not one that would generate the result you are describing.  Did you read the portion of the log that describes the results of the DATA step?  That would be the most important part.

 

The minor issue is that the informat $9. might read extra characters, including part of the QUANTITY value.  The solution would be to add this statement before the INPUT statement:

 

length variety $ 9;

 

Then the portion of the INPUT statement that reads VARIETY would become:

 

input ... @17 variety $ quantity;

 

My suspicion is that your DATA step contains an error, and an earlier version of FlowerSales is being used (one that does not contain SalesDate).  But you'll have to read the log to be able to tell.

Occasional Contributor
Posts: 17

Re: SAS Macro issue

Posted in reply to Astounding

Thanks for your quick reply.  I really appreciate that.

As you mentioned I modified the code as below;

lenght Variety $9;

input customerID $4. @6 SalesDate mmddyy10. @17 Variety $ @28 quantity 3.;

 

Now it works.  

Thanks a lot Smiley Happy

Occasional Contributor
Posts: 17

Re: SAS Macro issue

Posted in reply to Astounding

Hello my friend

I have made little modification on this file as below.  But I am not getting output. Am I doing something wrong here?


data flowersales;
infile 'C:\Users\location\Documents\My SAS Files(32)\democode\tropicalsales.txt' dlm=',';
length Variety $9;
input customerID $ SalesDate mmddyy10.  Variety $  quantity ;
IF Variety = "&flowertype";
run;
proc print data = flowersales;
format SalesDate WORDDATE18.;
TITLE "Sales of &flowertype";
run;

 

data:

240W,02-07-2008,Ginger,120
240W,02-07-2008,Protea,180
356W,02-08-2008,Heliconia,60
356W,02-08-2008,Anthurium,300
188R,02-11-2008,Ginger,24
188R,02-11-2008,Anthurium,24
240W,02-12-2008,Heliconia,48
240W,02-12-2008,Protea,48
356W,02-12-2008,Ginger,240

Super User
Posts: 5,516

Re: SAS Macro issue

Posted in reply to sas_td2016

You will need to post the log from running this.  It could be anything ... like are you checking the right place to look for output?  But let's start with examining the log.

Super User
Posts: 19,869

Re: SAS Macro issue

Posted in reply to sas_td2016

Since you've marked this question solved it may be appropriate to start a new question as others won't check this thread. 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 377 views
  • 0 likes
  • 3 in conversation