09-20-2018
arunvaibhav2
Calcite | Level 5
Member since
11-02-2017
- 7 Posts
- 1 Likes Given
- 0 Solutions
- 0 Likes Received
-
Latest posts by arunvaibhav2
Subject Views Posted 911 08-24-2018 01:53 PM 1565 11-16-2017 12:01 AM 1567 11-15-2017 11:57 PM 1568 11-15-2017 11:55 PM 3028 11-15-2017 09:21 PM 1606 11-15-2017 08:42 PM 851 11-15-2017 08:00 PM -
Activity Feed for arunvaibhav2
- Posted How do I get Cleaned Output? on SAS Programming. 08-24-2018 01:53 PM
- Posted Re: Need help in Macro Error - Macro prints previous result! on SAS Programming. 11-16-2017 12:01 AM
- Posted Re: Need help in Macro Error - Macro prints previous result! on SAS Programming. 11-15-2017 11:57 PM
- Liked Re: Need help in Macro Error - Macro prints previous result! for ChrisNZ. 11-15-2017 11:57 PM
- Posted Re: Need help in Macro Error - Macro prints previous result! on SAS Programming. 11-15-2017 11:55 PM
- Posted Re: ERROR: A character operand was found in %IF condition where a numeric operand is required. on SAS Programming. 11-15-2017 09:21 PM
- Posted Need help in Macro Error - Macro prints previous result! on SAS Programming. 11-15-2017 08:42 PM
- Posted My Macro resolved to previous result while log resolves to current. Any help? on SAS Programming. 11-15-2017 08:00 PM
-
Posts I Liked
Subject Likes Author Latest Post 1
08-24-2018
01:53 PM
Hello All, Problem: I have a Data Cleaning problem. I have this data where There is a Product manufacturer and Product Brand. Each manufacturer has several Brands. The brands data is manually entered and is messy. I need to check the data which is manually entered and create standard brand name. Here is the example, Product Manufacturer Product Brand Abila Taquila Abila TAQUILA Abila tAqueela Tambola Daqueela Tambola Taqueela Abila daqueela Tambola Samila Here is the desired output, Product Manufacturer Product Brand Standard Brand Abila Taquila Taquila Abila TAQUILA Taquila Abila tAqueela Taquila Tambola Daqueela Daqueela Tambola Taqueela Taquila Abila daqueela Daqueela Tambola SAMmila Samila The next step would be get the count of unique combinations. Which I can achieve once I got the above output. The problem here is, I need to do this for only 2 Manufacturers but all brands there are (~3,000) of them. Approach: I did run a select distinct brand name and got around 200,000 names which are different combinations of same name. For example, the result retuned as Abila abila abla cabla Cabl Cabla .. So, Since I cannot extract all possible combinations, I extracted count as well, which gave me most frequent used notation, I ran a program to delete all less frequent notations of brand name. Now I have list of Product Brands ~90,000 But, I cannot code multiple WHEN … THEN Statements like below (I should code (90,000) of them, which is impossible) CASE
WHEN MISC.PRD_BRAND_NM Like 'ABila%' OR MISC.PRD_BRAND_NM Like 'abila%' OR MISC.PRD_BRAND_NM Like 'ab%' THEN 'Abila' AS Standard_name I’m looking is there a way that I create a macro and pass all variables through a function to create standard name? Some thing like below, CASE
WHEN MISC.PRD_BRAND_NM Like &pass. OR MISC.PRD_BRAND_NM Like &pass. OR MISC.PRD_BRAND_NM Like &pass. THEN &pass. AS Standard_name Do <this function> until <end of all brands> <this function> To replace macro variables with all combinations. Or any other way I can achieve the objective? Thanks a ton!
... View more
11-16-2017
12:01 AM
Thanks! But, got this, ERROR 22-7: Invalid option name FIRST_OBS.
... View more
11-15-2017
11:57 PM
Thanks a lot!! That worked!
... View more
11-15-2017
11:55 PM
Wow! Great approach and explanation! Thanks a lot!
... View more
11-15-2017
09:21 PM
You should use same format while using and passing SAS macro parameter. When your macro parameter passing value has characters, should use %str every where. I have modified the code as below. %macro SAS_display(value=);
/*1st line*/%if &value = %str(SAS-A) %then %do; %let valueplay = %str(SAS-A); %put The value of valueplay is &valueplay; %end;
/*2nd line*/%if &value = %str(SAS_B) %then %do; %let valuedisplay = %str(SAS_B); %put The value of valuedisplay is &valuedisplay; %end;
/*3rd line*/%if &value = SAS %then %do; %let programdisplay = SAS; %put The value of programdisplay is &programdisplay; %end;
/*4th line*/%if &value = %str(SAS%-A) %then %do; %let valueplay = %str(SAS-A); %put The value of valueplay is &valueplay; %end;
/*5th line*/%if &value = %str(SAS%_B) %then %do; %let valuedisp =%str(SAS-b); %put The value of valueplay is &valueplay; %end;
%mend SAS_display;
%SAS_display(value=SAS)
%SAS_display(value=SAS_B) When you call what ever value in the macro, corresponding step executes and macro variables resolves correctly. Hope this helps.
... View more
11-15-2017
08:42 PM
Hello All, Below is the code. options mprint symbolgen;
%macro highest(num=);
%global g_num;
%let g_num = #
proc sort data=have;
by descending salary;
run;
data want;
set have;
if _n_ = &g_num then do;
output;
stop;
end;
run;
proc print data = want;
%if &g_num = 1 %then %do;
title "This is 1st Highest Salary";
%end;
%else %if &g_num = 2 %then %do;
tilte "This is 2nd Highest Salary";
%end;
%else %if &g_num = 3 %then %do;
title "This is 3rd Highest Salary";
%end;
%else %do;
title "This is &g_num.th Highest Salary";
%end;
%symdel g_num;
%mend highest; The program runs fine when I execute the macro call along with it's definition. But, when I change the value in the macro parameter and execute the macro line alone, the log resolves correctly but the output prints previous result. Would like to know what's wrong with the code above. Any help is highly appreciated. Thanks, Vaibhav
... View more
11-15-2017
08:00 PM
Hello all, Below is the code. options mprint symbolgen;
data have;
input EMPNO Salary empcode $;
cards;
111 4000 A
112 6000 A
114 2000 A
115 8000 A
223 2000 B
226 1000 B
228 3000 B
300 500 C
333 700 C
345 300 C
356 200 C
320 700 C
;
run;
%macro highest(num=);
%global g_num;
%let g_num = #
proc sort data=have;
by descending salary;
run;
data want;
set have;
if _n_ = &g_num then do;
output;
stop;
end;
run;
proc print data = want;
%if &g_num = 1 %then %do;
title "This is 1st Highest Salary";
%end;
%else %if &g_num = 2 %then %do;
tilte "This is 2nd Highest Salary";
%end;
%else %if &g_num = 3 %then %do;
title "This is 3rd Highest Salary";
%end;
%else %do;
title "This is &g_num.th Highest Salary";
%end;
%symdel g_num;
%mend highest;
%highest(num=11) I want to print nth highest salary. At first my program executes fine. And If you execute changing the parameter value(num) in macro %highest, along with macro it yields correct results. But if I execute only the line %highest(num=11) by changing the value, without including the macro definition in the execution, it shows results of previous value. What's wrong with this code ? Thanks, Vaibhav
... View more