SAS Communities Library

We’re smarter together. Learn from this collection of community knowledge and add your expertise.
BookmarkSubscribeRSS Feed

How to download your Netflix history and import to SAS

Started ‎03-10-2021 by
Modified ‎04-08-2021 by
Views 22,463

Recent blog posts and newsletter articles showed off how I used SAS to analyze my Netflix history. This sparked curiosity among several readers who wanted to do something similar with their own data. In this article, I'll show how to download and read this data into SAS.

 

Your Netflix viewing history is available from your Netflix account and profile settings.  Every so often the interface changes, so this may move around over time.  At the time of this writing I find my viewing history here, under the "Profile and Parental Controls" section:

 

ChrisHemedinger_0-1615415271280.png

 

Clicking View will lead you to a list of your most recent activity.  But the magic button is the Download all option on the bottom right of the page:

 

ChrisHemedinger_1-1615415271176.png

 

This will download a "NetflixViewingHistory.csv" file via your browser, with all of your streaming activity recorded since you established your account.  The CSV has a simple format: one record per streamed title, with two fields.

 

ChrisHemedinger_2-1615415271262.png

 

You might have multiple profiles associated with your account, used by different family members to control preferences, lists, favorites, etc.  If that's the case, you must repeat this download process for each profile in your account to gather a full view.  In my case, we have 5 different profiles in our account.  I named each CSV file with the associated profile name as I downloaded them.

 

NOTE: You do not have to trigger the "Download your personal information" option that Netflix provides. That produces more data than I've captured here -- but it takes Netflix a day or longer to fulfil the request.  Using the method I've shown above, you have instant access to simplified data for your viewing activity.

Oh, you don't have Netflix viewing data? Use mine.

No Netflix account? Too embarrassed by your viewing habits to analyze it yourself? I volunteer my data as tribute.  Here's a SAS program that fetches it from GitHub and imports the basics into SAS. (This program uses GIT* functions that require SAS 9.4 Maint 6 or SAS Viya 3.5 or later. It should work in SAS University Edition or SAS OnDemand for Academics.)

 

/* Utility macro to check if folder is empty before Git clone */ 
%macro FolderIsEmpty(folder);
  %local memcount;
  %let memcount = 0;
	%let filrf=mydir;
	%let rc=%sysfunc(filename(filrf, "&folder."));
  %if &rc. = 0 %then %do;
  	%let did=%sysfunc(dopen(&filrf));
  	%let memcount=%sysfunc(dnum(&did));
  	%let rc=%sysfunc(dclose(&did));
    %let rc=%sysfunc(filename(filrf));
  %end;
  /* Value to return: 1 if empty, else 0 */
  %sysevalf(&memcount. eq 0)
%mend;

options dlcreatedir;
%let repopath=%sysfunc(getoption(WORK))/sas-netflix-git;
libname repo "&repopath.";
data _null_;
 if (%FolderIsEmpty(&repoPath.)) then do;
    	rc = gitfn_clone( 
      	"https://github.com/cjdinger/sas-netflix-git", 
      	"&repoPath." 
    				); 
    	put 'Git repo cloned ' rc=; 
    end;
    else put "Skipped Git clone, folder not empty";
run;

filename viewing "&repopath./NetflixData/*.csv";
data viewing (keep=title date profile);
 length title $ 300 date 8 
        profile $ 40 in $ 250;
 format date date9.;
 infile viewing dlm=',' dsd filename=in firstobs=2;
 profile=scan(in,-1,'\/');
 input title date:??anydtdte.;
 if date^=. and title ^="";
run;

 

If you want to take it a step further and parse the Netflix titles, you can create some "feature" variables as you read in the data:

 

data viewing;
 length title $ 300 date 8 
        maintitle $ 60 episode $ 40 season $ 12 
        profile $ 40 in $ 250;
 informat date mmddyy.;
 format date date9.;
 infile viewing dlm=',' dsd filename=in firstobs=2;
 profile=scan(in,-1,'\/');
 input title date;
 array part $ 60 part1-part4;
 do i = 1 to 4;
	part{i} = scan(title, i, ':',);
  if (find(part{i},"Season")>0)
   then do;
     season=part{i};
   end;
	end;
 drop i;
 maintitle = part{1};
 episode = part{3};
 if Title ^= "Title";
run;

 

 Example output:

ChrisHemedinger_3-1615416136079.png

 

If you want to start from just my data files yourself, you can find those in this GitHub folder.

Version history
Last update:
‎04-08-2021 11:13 AM
Updated by:
Contributors

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags