• Home
  • About Us
  • Contact Us
  • DMCA
  • Sitemap
  • Privacy Policy
Saturday, April 1, 2023
Insta Citizen
No Result
View All Result
  • Home
  • Technology
  • Computers
  • Gadgets
  • Software
  • Solar Energy
  • Artificial Intelligence
  • Home
  • Technology
  • Computers
  • Gadgets
  • Software
  • Solar Energy
  • Artificial Intelligence
No Result
View All Result
Insta Citizen
No Result
View All Result
Home Artificial Intelligence

Making a Microsoft Excel report utilizing SAS, Python and SQL!

Insta Citizen by Insta Citizen
December 31, 2022
in Artificial Intelligence
0
Making a Microsoft Excel report utilizing SAS, Python and SQL!
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


The addition of the PYTHON process and Python editor in SAS Viya permits customers to execute Python code in SAS Studio. This new functionality in SAS Viya provides one other instrument to SAS’s current assortment. With this addition I assumed, how can I make the most of this new discovered energy?

On this instance, I am going to hold it easy. I need to create a Microsoft Excel report utilizing a mixture of SAS, Python and SQL. I am going to use knowledge that is saved in a SAS library; nonetheless, the library could possibly be utilizing knowledge saved anyplace, like a path, database or within the cloud. I am going to write a program that executes the next:

All code used on this publish is situated on GitHub, right here.

Set folder path and file title

To start, I am going to create a macro variable to specify the output folder path and Microsoft Excel workbook title.

%let path=/*Enter your output folder path*/;
%let xlFileName = myExcelReport.xlsx;

Put together knowledge

Additional, I am going to put together the info utilizing the SAS DATA step. I am going to use the out there sashelp.automobiles desk, create a brand new column named MPG_Avg, and drop pointless columns. As an alternative of utilizing the DATA step you should utilize Python or SQL to arrange the info. No matter instrument works greatest for you.

knowledge work.automobiles;
    set sashelp.automobiles;
    MPG_Avg=imply(MPG_City, MPG_Highway);
    drop Wheelbase Weight Size;
run;

Create the Microsoft Excel workbook

After the info is prepared, I am going to use the ODS EXCEL assertion to create the Excel spreadsheet. The next ODS choices are used:

  • FILE – specifies the file path and title.
  • STYLE – modifies the looks of the SAS output
  • EMBEDDED_TITLES – specifies titles ought to seem within the worksheet
  • SHEET_INTERVAL – permits handbook management when to create a brand new worksheet
ods excel file="&path./&xlFileName" 
		  model=ExcelMidnight   
		  choices(embedded_titles="on");

Worksheet 1

Print the info utilizing SAS

With the ODS EXCEL vacation spot open I am going to title the primary worksheet Information, and manually specify when a brand new sheet is created. Subsequent, I am going to use the PRINT process to print the detailed knowledge to Excel. The PRINT process will print your complete SAS knowledge set with the related codecs and kinds to Excel.

* Sheet 1 - Print the info utilizing SAS *;
ods excel choices(sheet_name='Information' sheet_interval='none');
title peak=16pt coloration=white "Detailed Automobile Information";
proc print knowledge=work.automobiles noobs;
run;

Worksheet 2

Create violin plots utilizing Python

Subsequent, I need to create violin plots on a brand new worksheet named Origin_MPG. Now, these will be created in SAS, however I personally discovered the matplotlib bundle in Python a bit simpler to make use of . With the PYTHON process, I can embrace the Python code inside the SAS program (or you possibly can reference a .py file) to create the visualization. Then I am going to use the SAS.pyplot methodology to avoid wasting and render the visualization. For the reason that pyplot callback renders the picture within the outcomes tab, it exports the picture to the Excel workbook by default.

First I am going to use ODS EXCEL to create the brand new worksheet and the TITLE assertion so as to add a title to the Excel worksheet.

ods excel choices(sheet_name='Origin_MPG' sheet_interval='now');
title justify=left peak=16pt coloration=white "Analyzing MPG by Every Automobile Origin";

Then I am going to execute the PYTHON process to execute my Python code to create the violin plot.

* Create violin plots utilizing Python *;
proc python;
submit;
 
##
## Import packages and choices
##
 
import pandas as pd
import matplotlib.pyplot as plt
plt.model.use('fivethirtyeight')
outpath = SAS.symget('path')
 
##
## Information prep for the visualization
##
 
## Load the SAS desk as a DataFrame
df = (SAS
      .sd2df('work.automobiles')                 ## SAS callback methodology to load the SAS knowledge set as a DataFrame
      .loc[:,['Origin','MPG_Avg']]        ## Maintain the mandatory columns
)
 
 
## Create a sequence of MPG_Avg for every distinct origin for the violin plots
listOfUniqueOrigins = df.Origin.distinctive().tolist()
 
mpg_by_origin = {}
for origin in listOfUniqueOrigins:
    mpg_by_origin[origin] = df.question(f'Origin == @origin ').MPG_Avg
 
 
##
## Create the violin plots
##
 
## Violin plot
fig, ax = plt.subplots(figsize = (8,6))
ax.violinplot(mpg_by_origin.values(), showmedians=True)
 
## Plot look
ax.set_title('Miles per Gallon (MPG) by Origin')
rename_x_axis = {'place': [1,2,3], 'labels':listOfUniqueOrigins}
ax.set_xticks(rename_x_axis['position'])
ax.set_xticklabels(rename_x_axis['labels'])
 
## Save and render the picture file
SAS.pyplot(plt, filename='violinPlot',filepath=outpath)
 
endsubmit;
stop;
title;

SQL Aggregation

SQL is a particularly widespread and helpful language for knowledge analysts and scientists. I discover utilizing SQL for aggregation straightforward, so I’ll create a easy aggregation and add it under the visualization on the identical worksheet within the the Excel report.

* SQL Aggregation *;
title justify=left "Common MPG by Automobile Makes";
proc sql;
choose Origin, spherical(imply(MPG_Avg)) as AverageMPG
	from work.automobiles
	group by Origin
	order by AverageMPG desc;
stop;
title;

Add textual content

On the finish of the identical worksheet I am going to add some easy textual content utilizing the ODSTEXT process to offer some details about the info.

proc odstext;
   heading 'NOTES';
   p 'Utilizing the SASHELP.CARS knowledge. The next automobile Origins had been analyzed:';
   listing ;
      merchandise 'Asia';
      merchandise 'Europe';
      merchandise 'USA';
   finish;    
   p 'Created by Peter S';
stop;

Lastly, I am going to shut the ODS EXCEL vacation spot since I’m completed writing out to Excel.

Outcomes

That is it! Now I am going to execute your complete program and think about the Excel workbook.

Abstract

With the capabilities of SAS and the brand new capability to execute Python code in SAS Studio, groups have quite a lot of instruments in SAS Viya for his or her analytic wants.

Further sources

PYTHON Process documentation
SAS opens its code editor interface to Python customers
Utilizing PROC PYTHON to reinforce your SAS packages
ODS Excel Assertion



Source_link

READ ALSO

Discovering Patterns in Comfort Retailer Areas with Geospatial Affiliation Rule Mining | by Elliot Humphrey | Apr, 2023

Scale back name maintain time and enhance buyer expertise with self-service digital brokers utilizing Amazon Join and Amazon Lex

Related Posts

Discovering Patterns in Comfort Retailer Areas with Geospatial Affiliation Rule Mining | by Elliot Humphrey | Apr, 2023
Artificial Intelligence

Discovering Patterns in Comfort Retailer Areas with Geospatial Affiliation Rule Mining | by Elliot Humphrey | Apr, 2023

April 1, 2023
Scale back name maintain time and enhance buyer expertise with self-service digital brokers utilizing Amazon Join and Amazon Lex
Artificial Intelligence

Scale back name maintain time and enhance buyer expertise with self-service digital brokers utilizing Amazon Join and Amazon Lex

April 1, 2023
New and improved embedding mannequin
Artificial Intelligence

New and improved embedding mannequin

March 31, 2023
Interpretowalność modeli klasy AI/ML na platformie SAS Viya
Artificial Intelligence

Interpretowalność modeli klasy AI/ML na platformie SAS Viya

March 31, 2023
How deep-network fashions take probably harmful ‘shortcuts’ in fixing complicated recognition duties — ScienceDaily
Artificial Intelligence

New in-home AI device screens the well being of aged residents — ScienceDaily

March 31, 2023
RGB-X Classification for Electronics Sorting
Artificial Intelligence

TRACT: Denoising Diffusion Fashions with Transitive Closure Time-Distillation

March 31, 2023
Next Post
Worth 3D: Be Go-Getters – Blue Raven Photo voltaic

Worth 3D: Be Go-Getters - Blue Raven Photo voltaic

POPULAR NEWS

AMD Zen 4 Ryzen 7000 Specs, Launch Date, Benchmarks, Value Listings

October 1, 2022
Only5mins! – Europe’s hottest warmth pump markets – pv journal Worldwide

Only5mins! – Europe’s hottest warmth pump markets – pv journal Worldwide

February 10, 2023
Magento IOS App Builder – Webkul Weblog

Magento IOS App Builder – Webkul Weblog

September 29, 2022
XR-based metaverse platform for multi-user collaborations

XR-based metaverse platform for multi-user collaborations

October 21, 2022
Migrate from Magento 1 to Magento 2 for Improved Efficiency

Migrate from Magento 1 to Magento 2 for Improved Efficiency

February 6, 2023

EDITOR'S PICK

How deep-network fashions take probably harmful ‘shortcuts’ in fixing complicated recognition duties — ScienceDaily

Can the AI driving ChatGPT assist to detect early indicators of Alzheimer’s illness? — ScienceDaily

December 26, 2022
The Cooler Grasp MasterAir MA624 Stealth Will Price You

The Cooler Grasp MasterAir MA624 Stealth Will Price You

December 20, 2022
Google Cloud professional shares perception

Google Cloud professional shares perception

February 11, 2023
Creating a flexible vaccine to tackle Covid-19 in its many guises | MIT Information

Creating a flexible vaccine to tackle Covid-19 in its many guises | MIT Information

March 26, 2023

Insta Citizen

Welcome to Insta Citizen The goal of Insta Citizen is to give you the absolute best news sources for any topic! Our topics are carefully curated and constantly updated as we know the web moves fast so we try to as well.

Categories

  • Artificial Intelligence
  • Computers
  • Gadgets
  • Software
  • Solar Energy
  • Technology

Recent Posts

  • GoGoBest E-Bike Easter Sale – Massive reductions throughout the vary, together with an electrical highway bike
  • Hackers exploit WordPress plugin flaw that provides full management of hundreds of thousands of websites
  • Error Dealing with in React 16 
  • Discovering Patterns in Comfort Retailer Areas with Geospatial Affiliation Rule Mining | by Elliot Humphrey | Apr, 2023
  • Home
  • About Us
  • Contact Us
  • DMCA
  • Sitemap
  • Privacy Policy

Copyright © 2022 Instacitizen.com | All Rights Reserved.

No Result
View All Result
  • Home
  • Technology
  • Computers
  • Gadgets
  • Software
  • Solar Energy
  • Artificial Intelligence

Copyright © 2022 Instacitizen.com | All Rights Reserved.

What Are Cookies
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT