I use a customized setup within the Enhanced Editor which sets Emacs-like bindings for many tasks. For example, Move cursor down is assigned to C-n, Move cursor left is assigned to C-b, etc.
Unfortunately, whenever I need to reinstall SAS or use a different computer, I have to reassign everything by hand, a non-trivial process. I know it's possible to export keyboard macros as .kmf files. Are the assigned keys stored somewhere that I could back up?
I am using SAS 9.4 on Windows (otherwise I would just use Emacs).
Your sasuser.profile catalog contains preferences and settings, amongst other things. Copy that to the new sasuser folder and things should be as before.
Find your current SAS session sasuser path with %put %sysfunc(pathname(sasuser));
You can test this by creating a new SAS shortcut with a new -sasuser setting.
For example:
create folder c:\temp\sasuser
copy existing sasuser profile.sas7bcat file to the new sasuser folder
create a new SAS shortcut
edit properties and append -sasuser "c:\temp\sasuser" to the target.
open the shortcut
All your preferences and settings will be the same as you had in the old session.
Related
Is it possible to define and start a user prompt by starting a SAS EG program, a code? and if yes what's the syntax?
I suppose you refer to prompting for input from a data step or from macro code. That does not work in Enterprice Guide (EG), but there is another sollution.
Each EG project has a set of user defined prompts, which are actually just a global macro variable with specifications on the type of data it can contain, a default value etc.
Each step (program, transformation) can have prompts from the project associated to it. When you start that step, you will be prompted for values. In your code, you can then use these macro variables.
To start working with it: right click a step to which you want to associate a prompt and select properties. Activate the prompt tab and click the [Prompt Manager] button. (There is another way to open the prompt manager, but no-one ever uses it.)
In the prompt manager, you can define the prompts. Bear in mind they will be shared among the steps to which you associate them, so chose macro variable names and wordings that make sense throughout your project.
Once the prompts are defined, you can associate them with your step and use the macro variables where you need them.
Success
I am trying to find a solution to load an external data file but from a relative path, so when someone else open my PBIX it will still work on his/her computer.
many thanks.
Relative paths are *not* currently supported by Power BI.
To ease the pain, you can create a variable that contains the path where the files are located, and use that variable to determine the path of each table. That way, you only have to change a single place (that variable) and all the tables will automatically point to the new location.
Create a Blank Query, give it a name (e.g. dataFolderPath) and type in the path where your files are (e.g. C:\Users\augustoproiete\Desktop)
With the variable created, edit each of your tables in the Advanced Editor and concatenate your variable with the name of the file.
e.g. instead of "C:\Users\augustoproiete\Desktop\data.xlsx", change it to dataFolderPath & "\data.xlsx"
You can also vote/watch this feature request to be notified when it gets implemented:
Support relative path to excel/csv sources
You can use also the "Parameters" function.
1. Create a new Parameter like "PathExcelFiles"
Parameter_ScreenShot
Edit your "Source" entry
SourceEntry_ScreenShot
Done !
I don't think this is possible yet.
Please add your support for this idea so the Microsoft Power BI team will be more likely to add this as a new feature.
I couldn't bear the fact that there is no possibility to use relative paths, but finally I had to...
So I tried to find a half-decent acceptable workaround.
Using Python-Script it is at least possible to get access to the users %HOME% directory.
let
PySource = Python.Execute("from pathlib import Path#(lf)import pandas as pd#(lf)dataset = pd.DataFrame([[str(Path.home())]], columns = [1])"),
homeDir = Text.Trim(Lines.ToText(PySource{[Name="dataset"]}[Value][1])),
...
The same should be possible with R-Script but didn't do it.
Anybody knows any better solution to get the %HOME% directory inside "Power" Query? I would be glad to have one.
Then I created two scripts inside my working directory install.bat:
#ECHO OFF
if exist "%HOME%\.pbiTemplatePath\filepath.txt" GOTO :ERROR
#This is are the key commands
mkdir "%HOME%\.pbiTemplatePath"
echo|set /p="%cd%" > "%HOME%\.pbiTemplatePath\filepath.txt"
GOTO :END
#Just a little message box
:ERROR
SET msgboxTitle=There is already another working directory installed.
SET /p msgboxBody=<"%HOME%\.pbiTemplatePath\filepath.txt"
SET tmpmsgbox=%temp%\~tmpmsgbox.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WSCRIPT "%tmpmsgbox%"
:END
and uninstall_all.bat:
#ECHO OFF
if exist "%HOME%\.pbiTemplatePath\filepath.txt" RMDIR /S /Q "%HOME%\.pbiTemplatePath\"
So in "Power" BI I did this:
let
PySource = Python.Execute("from pathlib import Path#(lf)import pandas as pd#(lf)dataset = pd.DataFrame([[str(Path.home())]], columns = [1])"),
homeDir = Text.Trim(Lines.ToText(PySource{[Name="dataset"]}[Value][1])),
workingDirFile = Text.Combine({homeDir, ".PbiTemplatePath\filepath.txt"} , "\"),
workingDir = Text.Trim(Lines.ToText(Csv.Document(File.Contents(workingDirFile),[Delimiter=";", Columns=1, QuoteStyle=QuoteStyle.None])[Column1])),
...
Now if my git-repository (containing a "Power" BI-template-file and some config-files saying the template where to load the data from and the install/uninstall-scripts). Install has to be executed once and nobody has to copy and paste any path.
I'd be glad about any suggestion of improvement. It's not the solution Gotham deserves... Gotham deserves a better one.
As mentioned by a few people, you can use a dataset parameter and reference that in your script. What I haven't seen mentioned is that you can change these values using an API call:
https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/update-parameters
I'm trying to make a permanent change to my SAS config file (sasv9.cfg). Specifically, I want to increase the MEMSIZE option from -MEMSIZE 2G to -MEMSIZE MAX.
The instructions from SAS on how to do this are on this page under *Overview of Changing SAS System Option Settings' ... http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#p0drw76qo0gig2n1kcoliekh605k.htm#p0273uv4qrgcrjn16vg7muluuhrz
Using SAS' text editor I am able to access the config file (sasv9.cfg) and make the changes to the appropriate line of code.
The problem is that SAS won't let me save those changes, stipulating that the 'administrator' has to approve them. I am the administrator but I don't know enough about how SAS' OS works to enable the save.
Any suggestions on workarounds to this issue would be most welcome.
You need to edit the file as an Administrator since I'm guessing you are on Windows,
Right click in notepad app and select run as an Administrator:
Then open the file sasv9.cfg through menu > file > open
tl;dr: Can SAS libraries be nested within one another in the Enhanced Editor Explorer?
I am working with code which generates a plethora of data sets. Although there are many individual data sets, they can be grouped into various categories. For instance, perhaps 30 of them are incoming "raw" data, another 50 are analysis "results" and the remaining 20 are "intermediate" steps.
Currently, all 100 data sets reside in the Work directory. They have been well named so that they appear next to one another in the SAS Explorer window. However, I would prefer to organize them in folders.
One way to do this is to create new directories within the temporary Work folder.
%let dirWORK = %sysfunc(pathname(Work));
options dlcreatedir;
libname raw "&dirWORK./raw";
libname interm "&dirWORK./intermediate";
libname results "&dirWORK./results";
As sub-directories of Work, these directories and their contents will be deleted when the session ends. This is agreeable.
Not agreeable is how the raw, iterm, and results libraries appear one level up in 'Active Libraries' instead of within the 'Contents of "Work"'. This behavior is somewhat counter-intuitive and awkward.
Is there a way to view the sub-folders of Work within the 'Contents
of "Work"' in the SAS Explorer?
Perhaps there's another way to separate the data sets (DCREATE?) which causes the Explorer window to behave like a typical file browser?
Libraries can contain many things.. But not other libraries. Your 'Active Libraries' will always show your (available) list of libraries at the same level, regardless of where or how they were defined:
One option if you'd like to view your datasets like a typical file browser is to use the Explorer window. Just click View / Explorer, and navigate to your datasets that way..
eg:
%let dirWORK =C:/temp/work;
options dlcreatedir;
libname raw "&dirWORK./raw";
libname interm "&dirWORK./intermediate";
libname results "&dirWORK./results";
data raw.test;
set sashelp.class;
run;
SAS librefs are just single words, so by definition there is no heirarchy. You could try using librefs that will place them next to each other alphabetically? Perhaps WORKIN, WORKMID, WORKOUT. Then they would sort in logical order.
You could use a file explorer to browse the directory structure you have created, but I don't think the SAS Explorer tool in SAS Display Manager can handle that.
DMS does have a file explorer tool you could try. You can start directly on your current WORK directory by running this command from the command line of any window, or via the DM statement in a program.
exproot dir="%sysfunc(pathname(work))" title="Work Directory"
There appears to be no ideal solution. The best I could devise requires the use of two part names, a non-trivial amount of extra code, a custom setup, and is potentially confusing to other programmers. The easiest configuration appears to be the default behavior: simply dumping all data sets in the Work library and sifting through all of them.
For prosperity, here is the best solution I could devise to organize things.
Understanding the Display Manager and Explorer Window
The Display Manager (DM) controls the various windows in the Enhanced Editor. This includes windows such as log, results, pgm, output and explorer. It is the latter which is of principle interest here.
A user may configure windows per session using the menus. There exist, however, a set of commands which may be used to automatically configure the DM for each session. When used with the AUTOEXEC.sas facility, this allows the user to 'permanently' configure the SAS editor to their preferences.
The default explorer view for the Enhanced Editor is the "Contents of 'SAS Environment'".
When the explorer window is selected, a tree hierarchy view can be toggled. There are several ways to do this. Here is one way:
Select the explorer window
View > Show Tree
Having to do this every time SAS is opened becomes a pain. After we clean up the library tree, we will automate this.
Remove any extraneous libraries
SAS loads a variety of libraries by default. These include WORK, SASHELP, and SASUSER, as well as others that are part of non-base products. In my case, the MAPS, MAPSGFK, and MAPSSAS libraries are also loaded (see above picture). As I never have used these (and likely never will), they only serve to clutter up my library directory. To remove these, one can edit their config file.
SAS implements a whole web of config files. On a Windows system, the likely relevant sasv9.cfg file is located here:
C:\Program Files\SASHome\SASFoundation\9.4\nls\en
You will need admin rights to edit it. Disregarding the DO NOT EDIT BELOW THIS LINE warning, comment out the the following using PL/I style comments.
Un-commented:
-MAPS !SASROOT\maps
-MAPSGFK !SASROOT\mapsgfk
-MAPSSAS !SASROOT\maps
Commented:
/* -MAPS !SASROOT\maps*/
/* -MAPSGFK !SASROOT\mapsgfk*/
/* -MAPSSAS !SASROOT\maps*/
Now when SAS opens, the MAPS, MAPSGFK, and MAPSSAS library will not be automatically loaded. Unfortunately, there does not seem to be a way to disable the loading of the SASUSER and SASHELP libraries. If someone knows how, please let me know!
Configure the Explorer Window
The explorer window can be 'configured' using the DM statement and the AUTOEXEC.sas facility.
Navigate to the directory containing SAS.EXE. On a default Windows installation, it is located here:
C:\Program Files\SASHome\SASFoundation\9.4
Create a SAS program named AUTOEXEC.sas containing the following code and place it in the directory which contains SAS.EXE. This step requires admin privileges. I find it easiest to create the file in a non-privileged environment and simply copy the AUTOEXEC.sas program into the directory.
Include this in the AUTOEXEC.sas program:
dm 'dmsexp; tree; expand libraries; expand work;';
When SAS intializes, the AUTOEXEC.sas code is executed before any user input is accepted. The above code does the following:
dmsexp - Brings the explorer window into command focus.
tree - Toggles the tree hierarchy view.
expand libraries - Within the "Active Libraries" pane, drills down into Libraries.
expand work - Within the "Active Libraries" pane, drills down into the Work library.
Each of these is a separate command and could be issued on separate lines. Instead of this, semi-colons are used to issue them in a single line.
Now when SAS is opened, the tree menu is available and the contents of the Work library are viewed. The picture below is somewhat deceiving. The "SAS Environment" pane is not set to a convenient width as pictured. It must be manually adjusted. If anyone has a way to automate this, please let me know!
Storing data sets in sub-folders
To ensure that data sets are deleted when the SAS session ends, sub-folders needs to be created within the temporary system folder where the Work library points to.
The following structure can now be followed:
/*Determine location of Work directory*/
%let dirWORK = %sysfunc(pathname(Work));
/*Allow LIBNAME statement to create new directories*/
options dlcreatedir;
/*Create sub-folders within the temporary Work directory
and assign librefs*/
libname raw "&dirWORK./raw";
libname interm "&dirWORK./intermediate";
libname results "&dirWORK./results";
Now, all the raw data sets can be assigned to the raw library. Within SAS, they will be logically separated from Work. That is, if the data set foobar is created in the raw library, it can only be accessed via raw.foobar. A statement such as data = foobar or data = work.foobar will not work. Yet because the raw library is in fact a sub-folder of Work, it will be deleted when the SAS session is ended.
Running some random code I found on the internet a few weeks ago has changed the pagesize and linesize defaults of my SAS output window. I don't remember what code it was though unfortunately. The current default pagesize is 15, which is generally way too small.
Does anyone know how to change the default?
I can change this using "options pagesize=80" or something but that only lasts for the current session. I can also change it in the GUI from Tools>Options>Output>Display but any changes won't save to my next session.
Any tips would be much appreciated! This is kind of excruciating. Thanks!
Your editor preferences are stored in a SAS catalog. Only 1 SAS session can open/write to this catalog at a single time. You can find out the location of the catalog that your SAS session is using by running this code:
proc options;run;
... And then search for SASUSER in the log.
If you launch SAS and it tries to use a SASUSER catalog that is already in use by another session, it will give you the message:
WARNING: Unable to copy SASUSER registry to WORK registry. Because of this,
WARNING: you will not see registry customizations during this session.
Are you seeing this message when you launch SAS? If so, it means that you have another instance of SAS open on your machine that has that catalog open. You have 2 options:
Close all instances of sas.exe on your machine (via task manager, be sure to check process names, not just the applications tab) then try making the change again.
Setup another shortcut to launch sas.exe. On this shortcut, specify a different SASUSER location like so:
sas.exe -SASUSER "d:\sas\profile2.cfg"
Also, I'm assuming you have the option to 'Save settings on exit' checked. Or if this isn't the case you can save your current settings by typing the command save into the command bar.
EDIT :
Some additional places to check that may override any profile settings:
Your sasv9.cfg file. Again, run proc options;run; and search for sasv9.cfg. It will give you the location of this file. If the file simply contains a list of other filenames, be sure to open up those 'included' files and check those.
Your autoexec file. If your SAS environment is specifying an autoexec file to load at launch, make sure it's not adjusting them there. Also if it is using an autoexec file, make sure you have all the loggin options turned on as the first thing that happens when SAS loads: option mprint notes source source2;.
Try right-clicking on SAS and choose 'Launch as Admininstrator'. If your profile is in a read-only location due to priveleges, perhaps your settings aren't being saved.
Look in your windows event log to see if SAS is loggin any errors there.
According to the SAS for Windows documentation, pagesize is controlled in part by the default printer. 15 is the minimum value, so it's possible that there is something wrong with your default printer and/or SAS is doing something odd (such as not finding one). If 'some random code' changed your default printer, you could simply try changing it back (see your SYSPRINT option).
I believe you can override this in your sasv9.cfg, commonly located in a path like C:\Program Files\SAS\SAS Foundation\9.4\nls\en\sasv9.cfg (varying based on what language version of SAS you use and your version, plus installation details), by simply adding -pagesize=80 or whatever you wish the default to be. You also can add options pagesize=80; to your autoexec.sas (or a new autoexec.sas if you don't have one already); see this paper or the documentation for more details on that.