If you see “Format $var1 was not found or could not be loaded.” message in the log, use format search options to access the permanent format to run the program.
options fmtsearch = (libname.dataset);
eg:
options fmtsearch = (fmt_pes.formats);
A journey of a thousand miles begins with the first step.
If you see “Format $var1 was not found or could not be loaded.” message in the log, use format search options to access the permanent format to run the program.
options fmtsearch = (libname.dataset);
eg:
options fmtsearch = (fmt_pes.formats);
/*select data from raw data set*/
data x;
set y;
where var1 = ‘xxx’ and var2 = ‘yyy’;
run;
/*check frequency on variables of interest*/
proc freq;
tables var1 var2;
run;
/*merge to get additional variables needed for analysis*/
proc sort data = x;
by var3;
proc sort data =z;
by var3;
data xz;
merge x (in =a) z;
by var3;
if a;
run;
The “Terms to Graduation” data is given 2 decimal places to help identify the small differences from year to year, while the data of the rest of the report are in integers.
VBA coding:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![Table Name].Value = “F. Terms to Graduation (Calendar Year)” Then
Me.[2008].DecimalPlaces = “2”
Me.[2009].DecimalPlaces = “2”
Me.[2010].DecimalPlaces = “2”
Me.[2011].DecimalPlaces = “2”
Me.[2012].DecimalPlaces = “2”
Me.[2013].DecimalPlaces = “2”
Me.[2014].DecimalPlaces = “2”
Else
Me.[2008].DecimalPlaces = “0”
Me.[2009].DecimalPlaces = “0”
Me.[2010].DecimalPlaces = “0”
Me.[2011].DecimalPlaces = “0”
Me.[2012].DecimalPlaces = “0”
Me.[2013].DecimalPlaces = “0”
Me.[2014].DecimalPlaces = “0”
End If
End Sub
Report results:
Y. I. An
To filter the report content in Access, one way is to develop the report on a query results and every time that you want to filter the report, just modify the query to include the filter criteria in the design view, then save the query, and the record source of the report will be automatically narrow down from the query results. This way has many benefits because you don’t have to create many reports with similar structure and your database looks cleaner. Sometime you do need to frequently produce reports for specific department, region or product. In that case besides the general report, you may want to make a copy of the report and use filter on load option for that specific product or department so you don’t have to go back and forth with the query.
Here is an example.
The report is for all the department, but I need to frequently print for 2 departments, so I put the department_ID in the property for filter. Notice the table name or the query name of the field needs to be filter is referenced as well. Also the Filter On Load property needs to be Yes.
Y. I. An
Objective: Print Access report by defined query results and generate pdf report for each selected record.
Reference: http://www.utteraccess.com/wiki/index.php/Recordsets_for_Beginners
Reference: http://www.utteraccess.com/wiki/index.php/RunSQL_vs_Execute
Reference:https://msdn.microsoft.com/en-us/library/office/ff192065.aspx
Basic coding:
Dim rst As DAO.Recordset
If you run into an error of “User-defined type not defined, you need to add “Microsoft DAO 3.6 object Library” to the reference library under “Tools” menu and then “Reference” item. Refer https://support.microsoft.com/en-us/kb/289664 for details.
DAO (Data Access Object) is different from ADO (Active Data Object). Both are types of recordsets. If the VBA is just used in Access only, it is good to use DAO.
Set rst currentDb. OpenRecordset (“Select ID from ids”)
To set a recordset object, using the OpenRecordset method of a database object.
The “… ” referred to above can be one of three things, passed as a literal string or a variable:
rst.close
Set rst= Nothing
“Clean up a recordset object.
These closing lines are very important and MUST be run (we include them in an exit procedure in case we have an error to ensure that the recordset is always closed and the object is dereferenced). Failure to do so may induce some very hard to track bugs.
With a recordset, we need to explicitly open it, and therefore it needs to be explicitly closed before the object pointer is destroyed.
If you used an object variable for the Database, you should also set this to Nothing (but, as it did not need to be “opened”, we need not “close” it).
VBA is supposed to automatically do this for us in case we don’t get it ourselves, but it doesn’t always catch it, and wierd things start happening when they are not caught.”– www.utteraccess.com
EOF
Do While rst.EOF = False
“Cursors and Position
BOF (beginning of file) and EOF (end of file) are always there. Records may not be. So, the first thing to do when opening a recordset is generally to check and make sure there are records in it. IF there are records, the RecordCount property of the recordset will return a nonzero value (not always the number of records though). Or, you can determine this by checking the BOF and EOF properties… if they are both true, there are no records.” –– www.utteraccess.com
Do loop until the end of the file. If the cursor reaches the end the file, the loop will be ended.
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, PdfFileNameToStore, False
Syntax: DoCmd.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding, OutputQuality)
“You can use the OutputTo method to output the data in the specified Access database object (a datasheet, form, report, module, data access page) to several output formats.” -msdn.microsoft
acOutputReport is an ObjectType Parameter. The types of object to output also includes acOutputForm, acOutputFunction, acOutputModule, acOutputQuery, acOutputserverView, acOutputStoredProcedure and acOutputTable.
stDocName is an ObjectName Parameter. “A string expression that’s the valid name of an object of the type selected by the ObjectType argument.”-msdn.sicrosoft
acFormatPDF is an OutputFormat Parameter. “An AcFormat constant that specifies the output format. If you omit this argument, Access prompts you for the output format. It can be one of the following AcFormat constants: acFormatASP, acFormatDAP, acFormatHTML, acFormatIIS, acFormatRTF, acFormatSNP, acFormatTXT, acFormatXLS” -msdn.microsoft
PdfFileNameToStore is an OutputFile Parameter. “A string expression that’s the full name, including the path, of the file you want to output the object to. If you leave this argument blank, Access prompts you for an output file name.” -msdn.microsoft
False is an AutoStart Parameter. “Use True (–1) to start the appropriate Microsoft Windows–based application immediately, with the file specified by the OutputFile argument loaded. Use False (0) if you don’t want to start the application. ” -msdn.microsoft
rst.MoveNext
This is the code to move the cursor. Similar codes like rst.MoveFirst, rst. MoveLast, rst.MoveNext, rst.MoveRrevious, rst.Move can move the cursor between the BOF and EOF. “By default, a recordset is opened with the cursor on the first record if there are records in the set. It is a good idea to check the BOF or EOF properties before navigating towards either one. “-– www.utteraccess.com
Here is a complete example:
Private Sub print_cpr()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strinsert As String
Dim mypath As String
Dim mypdf As String
Dim temp As String
Dim myReport As String
mypath = “X:\Work\CPR\1415\”
myReport = “rep_undergrad”
Set db = DBEngine.OpenDatabase(“X:\Work\AAP\Database\1415\1415 AAPR Undergraduate.mdb”)
Set rs = db.OpenRecordset(“Select * from tblCPR1415”, dbOpenSnapshot)
Do While Not rs.EOF
temp = rs(“Program_short”)
Debug.Print “The value of varialble temp is ” & temp
mypdf = rs(“Program_short”) & “.pdf”
DoCmd.OpenReport myReport, acViewPreview, , “[program_short]='” & temp & “‘”
DoCmd.OutputTo acOutputReport, “”, acFormatPDF, mypath & mypdf
DoCmd.Close acReport, myReport
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Description of the code:
The code is used to open a access database, then open a query with unique program_short value that can be passed on to the report. The result of the query is saved temporarily in the rs variable. The cursor starts with the first record in the rs recordset. The value of the first record is saved as the name of the pdf file, eg. AP-UG-EN which stands for a specific Faculty undergraduate English program. Open the undergraduate program report with the where condition of program short equal to “AP-UG-EN”. Output the pdf report to the defined the path with AP-UG-EN.pdf as file name. Cursor then move to the next record on the rs recordset until the end of the recordset to generate individual program report and output to pdf document. Once the cursor reaches the end of the recordset, the loop is finished and the program closes the rs recordset and clear the memory for both the recordset and database.
Application in Work:
I have designed standardized academic program reporting in Access with 2 layouts, one for Undergraduate and one for Graduate Programs. Use the above code and generate individual data sheets for hundreds for undergraduate and graduate programs. Then the datasheets can be distributed to the corresponding Faculty and program Directors.
Y. I. An
Proc Freq can produce output data sets that you can use for other SAS programming. One way is to specify the out= option in a TABLES statement and the other way is to have an OUTPUT statement. See the below SAS knowledge base for details.
I want to access the sas data table outside sas software and in Microsoft Access where I can edit the records more conveniently.
The version of sas I have is 9.3 and I googled the sas ODBC driver and came across the following link.
http://support.sas.com/downloads/browse.htm?cat=40#tab:2:
Initially, I installed the “Aug 2014” version, but it is for SAS 9.4 and didn’t work.
I uninstalled the sas ODBC for 9.4 and then installed the “July 2011” version which didn’t work either because I have Win 7.
Then I had to uninstalled ODBC for 9.3 and download the “Dec 2011” version.
Hope this time it works but it doesn’t. 🙁
Got this error message.
When launching setup.exe for ODBC installation. Got the following error message.
While having no success in installing SAS ODBC 9.3, I found some good reference resource on the website.
http://www.sascommunity.org/planet/blog/category/sql/
With some investigation, I found the odbcad32.exe hiding in a winsxs folder.
C:\Windows\winsxs\x86_microsoft-windows-m..-odbc-administrator_31bf3856ad364e35_6.1.7600.16385_none_44263d819f0aa19e
This might came from one of the windows service patch installed previously, but it is not the same ODBC administrator when I run from the “Control Panel” > “Administrative Tools”, which point to a different odbcad32.exe under C:\Windows\System32.
Apparently, the SAS ODBC 9.4 has already been recognized in the “ODBC Data Source Administrator”. Under the “System DSN” tab, click “Add”.
Find the “SAS” driver at the bottom of the list and click “Finish”.
In the “SAS ODBC Driver Configuration” window, there are 3 tabs, “General”, “Servers” and “Libraries”. Notice the Server name is defined as “__5001” which is the default “Local (Single User)” and if you change the name to something else, it will cause error in connection. Click “Configure…” on the “Servers” tab.
On the “Local Options” setting, check if the Path for sas.exe is correct and don’t change the default setting for “Startup parameters”. Click “OK” to go back.
Click “Library” tab and under the “Library Setting” give a Name for the library which holds the SAS data file you want to access through ODBC. In the “Host File”, provide the directory of the folder that contains the SAS data files. You can create many libraries for different SAS folders. Click “Add” to add the library and then “OK” to go back.
This completes the configuration of the “SAS ODBC Driver”.
I. A.
Come to renew my SAS license, I was given a txt file SAS93_xxxxxx_xxxxxxxx_win_X64_Wrkstn.txt.
Click “Start” > “Program”
A dialog box pops up where you can input the txt file name with the directory.
The renew license information has to match the operating system, if not, the new license will not be able to apply and change the site validation data.
For example, my computer is a ‘w32_7pro’ and the renew license’s OSNAME specifies ‘wx64-wks’, and I got the following error message.
It will generate a setimit.log (c:\program Files\sashome\x86\SASfoundation) with the detail information.
If the license file is right and you browse to the folder where it is saved.
Click “Next” and a dialog box will show the SAS installation data being verified with all the dates renewed to the new dates.
Then you need to identify the folder where SAS is installed. On my computer it is c:\Program Files\SASHome\x86\SASfoundation\9.3., then click “Renew”.
You will get a pop up that the setinit is successfully installed.
I.A.
Sometimes people were asking for data and you just provided it to them. If it is an annual completed static data, you don’t have to do the date stamp to keep a record on when you retrieve the data from the system. However, if it is an operational ongoing data with day-to-day changes and also the data is not officially published for the year, you might want to keep a record of the date for reference.
The SAS code here basically provides a date format that you want to show on the Excel file name. The format code itself is quite complicated, but you don’t have to remember it at all. Just copy and paste. There are many variations to it. Then use macro functions %unquote and %sysfunc to get date and time as part of the file name.
proc format;
picture mydtfmt
low-high = ‘%Y_%0m_%0d_%0I%0M%p’ (datatype=datetime);
run;
PROC EXPORT DATA= Section
OUTFILE= “C:\Documents\My SAS Files(32)\9.3\Exce\section_%unquote(%sysfunc(datetime(),mydtfmt.)).xlsx”
DBMS=EXCEL REPLACE;
SHEET=”section”;
RUN;
Output:
In Windows Explorer,
Develop an admission report.
1. On the “Home” tab, click “Edit” Grad Weekly Report.
2. In “Edit” mode, click “Criteria” tab.
3. Drag or double click the fields needed for the analysis from the left “Subject Areas” pane to add to the top “Selected Columns” pane.
4. Once added, drag-and-drop columns to reorder them.
5.Apply sorting on field. Please note if you already have sorted on other field(s), you need to use the “Add Ascending Sort” or “Add Descending Sort”, so that the second or more sort fields can be added (notice the sort number added next to the sorting symbol), otherwise the sort field will replace the previous sort setting.
6. Add Filters to the Analysis. Note the logical operator between the filters are “AND”, and you can click “AND” to change it to “OR”. Also pay attention to the indentation of the Filter criteria which is an indication of the grouping of the filters.
7. Save Analysis.
8. Click “Result” tab to modify layout of report results. The preliminary report is showing in the “Compound Layout” pane. Click the pen button to edit it.
9. Develop a pivot table design (most important report design). The fields selected previously on the “Selected Columns” under the “Criteria” tab are automatically plugged in the layout. You will need to make adjustments by dragging and dropping the fields to get the desired results. As you make the changes in the “Layout” pane, you will see the results on the top pane above the “Layout” pane.
9.1 Pivot Table Prompts. It gives you a report level filter for the end user to control.
Layout:
Results:
9.2. Section. It split the pivot table into sections by the value of the field selected. In the example, there will be a section for Masters programs and a section for PhD programs.
Layout:
Results:
9.3 Pivot Table Columns. Notice the “Measure Label” is on top of “Academic Year”, which means the “Academic Year” is a sub-column heading for each measurements. If the “Academic Year” is on top of the “Measure label”, then the column data for 2014 will be grouped together and 2015 data will be grouped together.
Layout:
Results:
9.4 Pivot Table Rows. For the row fields you can select to add subtotals for the measures. You can add the subtotal for the rows for the value grouping for each field (Notice the green ticket on the AutoSum symbol).
Layout:
Results:
9.5 Pivot Table Measures. These are the fields that you want to show the value and maybe also apply some calculation to show the variance or percentage change.
Layout:
Results:
9.6 Pivot Table Calculated field. I need a field to show the difference between the 2014 number and 2015 number. Because it applies to all the columns, the calculated field can be easily set up in “Columns”. “Academic Year”
Edit Calculated Item: I gave the label “Var.” to the calculated field. The formula is ‘2015’-‘2014’. We will talk about programing for dynamic calculated field in later topics. The result is shown as the illustration above.
Click save button and you just developed a basic report using Oracle Business Intelligence.
I. A.