I have an Excel (.xlsx) file that includes a column with an embedded hyperlink to a website. I would like to be able to have sas read the hyperlink and store it as a string in a new variable. I am not sure how to accomplish this. It is not an option to just create the hyperlink text manually because the source document hyperlinks are different in each cell and the part that changes is not available in any other location at this time. Please see the attached test document.
Summary: I would like to take the hyperlink in the "patient name" var and put it into a new var called "hyperlink" as a string value.
Can you post an extract of the data as dataset? See https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... for details.
Extracting a hyperlink should be possible with a regular expression.
Unfortunately no, the data is HIPAA protected. However, I did attach a mock raw excel file to assist.
Most likely you are good with VBA so you might have solved it by now. Just in case (and for future help to somebody) I am giving the steps below to extract the hyperlinks.
The code that you will type, as shown in the 4th image has been largely taken from here (http://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel). All I have done is shown you the process step by step. You can change the code to suit your need. The Code that you will type when you reach the fourth step is as below.
Sub ExtractHyperlink() Dim HL As Hyperlink For Each HL In ActiveSheet.Hyperlinks HL.Range.Offset(0, 1).Value = HL.Address Next End Sub
Now I am giving 6 steps in the form of consecutive 6 images. Please follow in sequence. Make sure you have a back up of the excel file on which you are going to work (just in case :-))
At this point, you can export it as csv and read using PROC IMPORT. The extension of this file would have changed from .xls/.xlsx to .xlsm, so EXCEL import will not work. I hope you get the idea.
Please let me know if this helped in any way.
Thank you.
I did something very similar using the code below.
Function GetURL(pWorkRng As Range) As String
GetURL = pWorkRng.Hyperlinks(1).Address
End Function
Thank You Everyone!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.