How do I export SAS text string to a Word document using DDE? - ms-word

I would like to export a string character from SAS to a word document (.docx) using Dynamic Data Exchange (DDE). Is this possible?
The SAS documentation on this is old and suggests I use the following commands:
filename testit dde 'winword|"file_path"!bookmark' notab;
data _null_;
file testit;
put 'insertstuff';
run;
SAS returns an error message:
ERROR: Physical file does not exist

Works for me.
filename testit dde 'winword|"e:\blah.docx"!bookmark' notab;
data null;
file testit;
put 'insertstuff';
run;
Steps:
Create a word document and save it in the specified path.
In word document, create a bookmark by going to Insert->Bookmark, give it a name of 'Bookmark' and press Add
Make sure both word and SAS are open. And that the document is open in word.
Run the SAS code.

Super late to the party, but there are a few issues that could cause that error:
You don't need "" around the filename, should just be:
filename testit dde 'winword|file_path!bookmark' notab;
data _null_;
file testit;
put '[Insert "stuff"]';
run;
The file path may be spelled incorrectly
You may not have permissions to the filepath. This is likely if it is a work machine.
To check:
Navigate to the filepath in the file explorer
Right click on the file
Open properties
Look for your username, click on it, and it will show you what permission you have
You have a missing/incorrect file extension (ie .doc not .docx ect)
Hope you were able to figure this out at the time :P

Related

Is it possible to extract metadata such as Content Created date from files - I can't get this with PowerShell

I need to extract the "Content Created" date out of thousands of files, but haven't been able to find a way to do this using PowerShell / other Command Line utility.
Does someone out there know a way to obtain this metadata? If so, please can you advise me. Thanks.
I've looked at various resources online, including this site, but haven't been successful thus far.
Here's a screenshot explaining what I'm trying to do.
I've been unable to find a native powershell cmdlet which does what you want. However, I found this article: Use PowerShell to Find Metadata from Photograph Files and the script it used: get file meta data function.
The article talks about image files, but the function is not specific for image files.
I tested it out on a folder containing a Word and an Excel file and the returned Metadata from the Word file contains the Content Created date. The Excel file does not contain/return that value. This is not unexpected as the Details tab of properties for the Excel file does not contain a Content Created value so it seems to be specific for Word files, and maybe some other file or document types.
Update:
You write that you need to extract this info from thousands of files, but if those files are anything but Word-files you probably won't be able to do that.
As far as I can tell this should work with the file types exposing the type of metadata you want. However, it seems that the ContentCreated property is unique to Word. I tried adding a text file (.txt), Acrobat PDF (.pdf), MS Access (.mdb), Excel (.xlxs) and a Word doc (.docx) file to my test folder and the only one that has/returns that metadata property is the Word file.
You should also be aware that the script seems to return metadata localized, so for me to programatically get the info i wanted I had to pipe the output of the script to Select-Object -Property Name,'InnehÄll skapat' (which is the Swedish name for Content created). So if you're running on a non-english system you may need to check what the output looks like before creating your Select-Object statement.
PowerQuery in Excel 2013 or later (data tab). Connect to data> Folder.

Compare Json Files in Beyond Compare

How can I compare two minified json files in beyond compare? Is there a built in file format for json? I'm looking to compare two pretty print representations of the underlying json objects.
In this thread a representative says:
While not in the box yet, we do have a JSON sorted format available for download in our Additional File Formats section:
With a link to Scooter Software Downloads
You can achieve this specialized diff functionality by defining a new file format conversion rule in beyond compare. This example was conducted in the Windows OS.
Step 0: Create a python conversion script to render the formatted json. Save the following python script somewhere on your harddrive
import json
import sys
sourceFile = sys.argv[1]
targetFile = sys.argv[2]
with open(sourceFile, 'r') as file_r:
# Load json data
data = json.load(file_r)
# Write formatted json data
with open(targetFile, 'w') as file_w:
json.dump(data, file_w, indent=4)
Step 1: Navigate in the BeyondCompare menu to: Tools-->File Formats...
Step 2: Create new file format entry by clicking on the + button and select Text Format
Step 3: Enter *.json into the file format's Mask field, and any description that will help you recall the file format's purpose.
Step 4: Define the file format's conversion settings. Select the Conversion tab and select External program (unicode filenames) from the pull down.
In the Loading field write the following shell command
python C:\Source\jsonPrettyPrint.py "%s" "%t"
Step 5: Press the Save button and optionally rename the file format by right clicking it in the File Formats Name and Mask table.
Further specializations of the json dumping could be considered by looking at the python documentation, eg sort_keys=True

Read a txt file by URL link in MATLAB

I have a txt file in the following URL path:
https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt
I wana read it into MATLAB. This file contains only an integer value. I used fopen() function, but it gives me error:
The file name contains characters that are not contained in the filesystem encoding. Certain operations may not work as expected.
Then, I used webread() and urlread(), but a big file is generating and not working as expected.
Is there any suggestion to how to read a simple value from an URL link?
It is because the url https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt refers to the dropbox page and not the file. If you add ?dl=1 at the end of the link, then it will refer to the file instead. e.g.
data = urlread('https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt?dl=1')
data =
'100'

How to publish a (csv, xlsx, etc) file from SAS DIS via email

So I have some SAS DIS jobs which create "kickout" data when run - by this I mean that if things run smoothly, none of the "kickout" data is generated, but it is known that there will be exceptions and I would like to have those exceptions put into a table and automatically emailed to me so that I am notified when something is behaving in a non-ideal manner.
I can create a transformation which will send an email containing the data I'm looking for, but the data is formatted as html and thus not in a form conducive to analysis. I'd like the transformation to email a .csv file which is more easily manipulated.
There is the option to send a .spk file but I'm having issues getting that to work and in any case am not sure it really suits my needs.
Is what I want possible, with or without the standard Publish to Email transformation provided by SAS DIS? Looking at the SAS DIS user guide I'm guessing that there is no pre-built transformation which does what I want, but can the base SAS code accomdate this requirement?
Thanks much!
The "Publish to Email transformation" uses ODS HTML to generate the output so you'll get a HTML output. If you want an XLS output then there is a way. You could change the extension of the output file to xls to generate xls file from the ODS HTML. This is an old way of generating xls from ODS HTML.
Now coming to the SPK file. This is something you should look into. Since you are looking into getting an xls/csv attachement which you can open and do some manipulation etc. SPK file is like a ZIP file. You can right click and unzip spk file. Basically you can put in all your files within a archive/spk file and get that emailed as attachement using the "Publish to Email Transformation"
To get this done, go to the properties of the "Publish to Email Transformation" and Under Publishing option=>
select Send report in an archive (.spk) file as an email attachment in the Select viewer file/attachment option field
provide folder/path where the spk file would be stored under Select path of where to store archive file containing report
provide the name of the spk file under Specify filename of archive file containing report
provide name=value pair of the package under Specify one or more desired package name/value pairs for package. For example this transformation is generating a PROC PRINT of an INPUT data set and the output file is c:\sushil\test.html then enter myname=(test.html) . The myname is for labeling purpose when you unzip the spk you should get test.html
Now Under REPORT SPECIFICATION option in the "Publish to Email Transformation" transformation select "Generate PROC PRINT from input table" and then enter the path and filename of generated report which based on our previous entry should be c:\sushil\test.html
Also, to select "Generate PROC PRINT from input table" you would need to right click the "Publish to Email Transformation" and select Ports -> Add Input Port. This how you can connect a table with the transformation. Now this is the minimum settings required to generate spk package from the transformation. Let me know if it helps!!
Note: This information is as per SAS DI Studio 4.6. I don't know if the transformation is updated in the newer version of DI Studio.

Extracting file names from an online data server in Matlab

I am trying to write a script that will allow me to download numerous (1000s) of data files from a data server (e.g, http://hydro1.sci.gsfc.nasa.gov/thredds/catalog/GLDAS_NOAH10SUBP_3H/2011/345/). Unfortunately, the names of the files in each directory are not formatted in a similar way (the time that they were created were appended to the end of the file name). I need to be able to specify the file name to subset the data (I have a special tool for these data types) and download it. I cannot find a function in matlab that will extract the file names.
I have looked at URLREAD, but it downloads everything including html code.
Thanks for your help!
You can easily parse the link.
x=urlread(url)
links=regexp(x,'<a href=''([^>]+)''>','tokens')
Reads every link, you have to filter all unwanted links.
For example this gets all grb files:
a=regexp(x,'<a href=''([^>]+.grb)''>','tokens')