BookmarkSubscribeRSS Feed
Ashwini
Calcite | Level 5

I have dataset as mention below

accountno   costomername    productname  date

AC111          RAM                   FREEZE             01NOV2011

AC222          HARI                   TV                   02DEC2011

AC333          GOPAL               COOKER         12NOV2011

AC444          NISHA                 FILTER             01JAN2012

AC111          RAM                    TV                   15JAN2012

AC333          GOPAL                FILTER             27JAN2012

AC222          HARI                    FREEZ              12JAN2012

Product code is

1 for freeze

2 for   TV

3 for filter

4 for cooker

I have to create  a dataset like as below mention query

1.If account no is AC111 is true the it display all the data of same account no.

2.create a dataset selecting account no and product code

3.create dataset by name      wise .

I have to write a macro using above condition in one macro code.

Kindly help me.

Regards,

Ashwini

3 REPLIES 3
SASJedi
SAS Super FREQ

Ashwini,

If you could include a sample of the data set(s) you want after the process is complete, it will be easier for us to help you devise a strategy to solve this problem.

Regards,

Mark

Check out my Jedi SAS Tricks for SAS Users
Ashwini
Calcite | Level 5

Dear Mark,

1:-1st query dataset is

accountno   costomername    productname  date

AC111          RAM                   FREEZE             01NOV2011

AC111          RAM                    TV                   15JAN2012

2:- 2nd query dataset is

if account no is AC111 and productcode is 1 ,dataset is

AC111          RAM                   FREEZE             01NOV2011

3:-3rd query is

if name is RAM then it show

AC111          RAM                   FREEZE             01NOV2011

AC111          RAM                    TV                   15JAN2012

Regards,

Ashwini

SASJedi
SAS Super FREQ

OK.  I'm still not sure I'm clear on the process - what you are trying to accomplish.  But if your intent is to specify Account number, name and product ID values and return the specified subsets, this code will produce the results you described.  If there is something more to this process, let me know.  Code follows:

data have;
  input accountno:$5. customername$5. productname:$6.  date:date9.;
  datalines;
AC111 RAM   FREEZE 01NOV2011
AC222 HARI  TV     02DEC2011
AC333 GOPAL COOKER 12NOV2011
AC444 NISHA FILTER 01JAN2012
AC111 RAM   TV     15JAN2012
AC333 GOPAL FILTER 27JAN2012
AC222 HARI  FREEZE 12JAN2012
;
run;

%macro Mention(ActNo, Name, ProdID);
  %if &ProdID=1 %then
    %let Prod=FREEZE;
  %else %if &ProdID=2 %then
    %let Prod=TV;
  %else %if &ProdID=3 %then
    %let Prod=FILTER;
  %else %if &ProdID=4 %then
    %let Prod=COOKER;
  %else
    %do;
      %put ERROR: Product ID must be 1,2,3 or 4. You entered &ProdID..;
      %return;
    %end;

  data Query1;
    set have;
    where accountno = "&ActNo";
  run;

  data Query2;
    set have;
    where AccountNo = "&ActNo" and ProductName="&Prod";
  run;

  data Query3;
    set have;
    where CustomerName= "&Name";
  run;

%mend;

%Mention(AC111, RAM, 1)

This code could be improved with some additional parameter checking / normalization. 

Regards,

Mark

Check out my Jedi SAS Tricks for SAS Users

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 995 views
  • 0 likes
  • 2 in conversation