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-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
  • 810 views
  • 0 likes
  • 2 in conversation