Sunday, 24 August 2025

269.STEP-BY-STEP YOUTUBE CHANNEL ANALYSIS WITH PROCS | PROC PRINT | PROC FREQ | PROC MEANS | PROC SQL | PROC SORT | TURBOCHARGE YOUR SAS SKILLS

STEP-BY-STEP YOUTUBE CHANNEL ANALYSIS WITH PROCS | PROC PRINT | PROC FREQ | PROC MEANS | PROC SQL | PROC SORT | TURBOCHARGE YOUR SAS SKILLS

 /*Creating a dataset for the top 10 Indian YouTube channels */

1. Create the dataset with at least 10 Indian YouTube channels 

options nocenter;

data yt_top10_india;

  length Channel_Name $40 Category $25;

  input Rank Channel_Name $ 1-32 Subscribers_M Videos Category $ 34-60;

  datalines;

1 T-Series 295 23624 Music_Entertainment

2 SET_India 184 155432 Entertainment

3 Zee_Music_Company 117 14265 Music

4 Goldmines 105 10691 Movies_Entertainment

5 Sony_SAB 101 99431 Comedy_Entertainment

6 ChuChu_TV_Nursery_Rhymes 96.4 874 Kids_Education

7 Zee_TV 90.8 210810 Entertainment

8 Colors_TV 80.4 254335 Entertainment

9 T-Series_Bhakti_Sagar 76.5 30162 Devotional_Music

10 Tips_Official 75.9 7934 Music

;

run;

proc print data=yt_top10_india;

  title "Top 10 Indian YouTube Channels (2025)";

run;

Output:

Top 10 Indian YouTube Channels (2025)

ObsChannel_NameCategoryRankSubscribers_MVideos
1T-SeriesMusic_Entertainment1295.023624
2SET_IndiaEntertainment2184.0155432
3Zee_Music_CompanyMusic3117.014265
4GoldminesMovies_Entertainment4105.010691
5Sony_SABComedy_Entertainment5101.099431
6ChuChu_TV_Nursery_RhymesKids_Education696.4874
7Zee_TVEntertainment790.8210810
8Colors_TVEntertainment880.4254335
9T-Series_Bhakti_SagarDevotional_Music976.530162
10Tips_OfficialMusic1075.97934

2. PROC MEANS: Descriptive Statistics 

proc means data=yt_top10_india mean min max std n;

  var Subscribers_M Videos;

  title "Subscribers & Video Statistics";

run;

Output:

Subscribers & Video Statistics

The MEANS Procedure

VariableMeanMinimumMaximumStd DevN
Subscribers_M
Videos
122.2000000
80755.80
75.9000000
874.0000000
295.0000000
254335.00
68.3800003
94167.18
10
10

3. PROC SORT: Sort channels by Subscribers in descending order 

proc sort data=yt_top10_india out=sorted_channels;

  by descending Subscribers_M;

run;

proc print data=sorted_channels;

run;

Output:

ObsChannel_NameCategoryRankSubscribers_MVideos
1T-SeriesMusic_Entertainment1295.023624
2SET_IndiaEntertainment2184.0155432
3Zee_Music_CompanyMusic3117.014265
4GoldminesMovies_Entertainment4105.010691
5Sony_SABComedy_Entertainment5101.099431
6ChuChu_TV_Nursery_RhymesKids_Education696.4874
7Zee_TVEntertainment790.8210810
8Colors_TVEntertainment880.4254335
9T-Series_Bhakti_SagarDevotional_Music976.530162
10Tips_OfficialMusic1075.97934


4. PROC FREQ: Frequency for Category variable 

proc freq data=yt_top10_india;

  tables Category / nocum nopercent;

  title "Frequency of Channel Category";

run;

Output:

Frequency of Channel Category

The FREQ Procedure

CategoryFrequency
Comedy_Entertainment1
Devotional_Music1
Entertainment3
Kids_Education1
Movies_Entertainment1
Music2
Music_Entertainment1

5. PROC SQL: Query channels with over 100 million subscribers 

proc sql;

  title "Channels with 100M+ Subscribers";

  select Channel_Name, Subscribers_M

  from yt_top10_india

  where Subscribers_M > 100;

quit;

Output:

Channels with 100M+ Subscribers

Channel_NameSubscribers_M
T-Series295
SET_India184
Zee_Music_Company117
Goldmines105
Sony_SAB101

6. PROC SQL: Aggregation by Category 

proc sql;

  title "Average Subscribers by Channel Category";

  select Category,

         count(*) as Channel_Count,

         mean(Subscribers_M) as Avg_Subscribers format=8.2

  from yt_top10_india

  group by Category;

quit;

Output:

Average Subscribers by Channel Category

CategoryChannel_CountAvg_Subscribers
Comedy_Entertainment1101.00
Devotional_Music176.50
Entertainment3118.40
Kids_Education196.40
Movies_Entertainment1105.00
Music296.45
Music_Entertainment1295.00

7. PROC SQL: Limit (top 5 by videos) using OUTOBS= 

proc sql outobs=5;

  title "Top 5 Channels by Number of Videos";

  select Channel_Name, Videos

  from yt_top10_india

  order by Videos desc;

quit;

Output:

Top 5 Channels by Number of Videos

Channel_NameVideos
Colors_TV254335
Zee_TV210810
SET_India155432
Sony_SAB99431
T-Series_Bhakti_Sagar30162

8. Macro: Print Top N Channels (by Subscribers) 

%macro print_top_channels(n);

  proc sql outobs=&n;

    title "Top &n YouTube Channels by Subscribers";

    select *

    from yt_top10_india

    order by Subscribers_M desc;

  quit;

%mend print_top_channels;


%print_top_channels(5);

Output:

Top 5 YouTube Channels by Subscribers

Channel_NameCategoryRankSubscribers_MVideos
T-SeriesMusic_Entertainment129523624
SET_IndiaEntertainment2184155432
Zee_Music_CompanyMusic311714265
GoldminesMovies_Entertainment410510691
Sony_SABComedy_Entertainment510199431

9. Macro: Loop Over Categories and Print Channels by Category 

%macro analyze_by_category;

   Gather unique categories into macro variables 

  proc sql noprint;

    select distinct Category into :cat1-:cat10

    from yt_top10_india;

    %let catcount=&sqlobs;

  quit;


  %do i=1 %to &catcount;

    %let currcat=&&cat&i;

    proc print data=yt_top10_india noobs;

      where Category="&currcat";

      title "YouTube Channels in Category: &currcat";

    run;

  %end;

%mend analyze_by_category;


%analyze_by_category

Output:

YouTube Channels in Category: Comedy_Entertainment

Channel_NameCategoryRankSubscribers_MVideos
Sony_SABComedy_Entertainment510199431

YouTube Channels in Category: Devotional_Music

Channel_NameCategoryRankSubscribers_MVideos
T-Series_Bhakti_SagarDevotional_Music976.530162

YouTube Channels in Category: Entertainment

Channel_NameCategoryRankSubscribers_MVideos
SET_IndiaEntertainment2184.0155432
Zee_TVEntertainment790.8210810
Colors_TVEntertainment880.4254335

YouTube Channels in Category: Kids_Education

Channel_NameCategoryRankSubscribers_MVideos
ChuChu_TV_Nursery_RhymesKids_Education696.4874

YouTube Channels in Category: Movies_Entertainment

Channel_NameCategoryRankSubscribers_MVideos
GoldminesMovies_Entertainment410510691

YouTube Channels in Category: Music

Channel_NameCategoryRankSubscribers_MVideos
Zee_Music_CompanyMusic3117.014265
Tips_OfficialMusic1075.97934

YouTube Channels in Category: Music_Entertainment

Channel_NameCategoryRankSubscribers_MVideos
T-SeriesMusic_Entertainment129523624

10. Advanced - Calculate and display percent share of total subscribers per channel 

proc sql noprint;

  select sum(Subscribers_M) into :total_subs from yt_top10_india;

quit;


proc sql;

  title "Share of Subscribers by Channel";

  select Channel_Name,

         Subscribers_M,

         (Subscribers_M/&total_subs)*100 as Percent_Share format=6.2

  from yt_top10_india

  order by Percent_Share desc;

quit;

Output:

Share of Subscribers by Channel

Channel_NameSubscribers_MPercent_Share
T-Series29524.14
SET_India18415.06
Zee_Music_Company1179.57
Goldmines1058.59
Sony_SAB1018.27
ChuChu_TV_Nursery_Rhymes96.47.89
Zee_TV90.87.43
Colors_TV80.46.58
T-Series_Bhakti_Sagar76.56.26
Tips_Official75.96.21

11. Data step + procs: Mark all music-related channels and analyze them 

data music_channels;

  set yt_top10_india;

  if index(Category,'Music') > 0 then MusicFlag = 1;

    else MusicFlag = 0;

run;


proc print data=music_channels;

  title "Music-related Channels Flagged";

run;

Output:

Music-related Channels Flagged

ObsChannel_NameCategoryRankSubscribers_MVideosMusicFlag
1T-SeriesMusic_Entertainment1295.0236241
2SET_IndiaEntertainment2184.01554320
3Zee_Music_CompanyMusic3117.0142651
4GoldminesMovies_Entertainment4105.0106910
5Sony_SABComedy_Entertainment5101.0994310
6ChuChu_TV_Nursery_RhymesKids_Education696.48740
7Zee_TVEntertainment790.82108100
8Colors_TVEntertainment880.42543350
9T-Series_Bhakti_SagarDevotional_Music976.5301621
10Tips_OfficialMusic1075.979341

proc means data=music_channels mean min max;

  title "Summary Statistics for Music Channels";

  where MusicFlag=1;

  var Subscribers_M;

run;

Output:

Summary Statistics for Music Channels

The MEANS Procedure

Analysis Variable : Subscribers_M
MeanMinimumMaximum
141.100000075.9000000295.0000000

proc sql;

  title "Music Channels, Descending by Subscribers";

  select Channel_Name, Subscribers_M

  from music_channels

  where MusicFlag=1

  order by Subscribers_M desc;

quit;

Output:

Music Channels, Descending by Subscribers

Channel_NameSubscribers_M
T-Series295
Zee_Music_Company117
T-Series_Bhakti_Sagar76.5
Tips_Official75.9



To Visit My Previous Proc  Means And Nway Option:Click Here
To Visit My Previous Proc Means And CharType Option:Click Here
To Visit My Previous SAS Functions:Click Here
To Visit My Previous Length Statement Using In Many Ways:Click Here




Follow Us On : 




--- FOLLOW OUR BLOG FOR MORE INFORMATION.

--->PLEASE DO COMMENTS AND SHARE OUR BLOG.

No comments:

Post a Comment