Hi All,
Any help would be appreciated.
I am actually creating a sas portal using stored process along with HTML.
I have actually created a code for the layout of the portal. now I have to integrate the data into the portal using HTML.
Could anyone help me how to bring the data which is present as sas dataset into the HTML Div section,
part of the code here below :
put '<tr> ';
put '<td>';
put ' <br /> ';
put '<div id="myDiv" name="myDiv" title="S/No. Staff & Admin" style="font-family: Helvetica; font-size: 12pt; "> ';
put ' <div id="subDiv1" name="subDiv1" title="S/No. Staff & Admin" > ';
put ' <h5>S/No. Staff & Admin</h5> ';
put ' <p><a href="www.google.com">Google</a> ';
put ' <a href="https://www.google.com/html/"><img src="../SASStoredProcess/adhoc/images/icon_csv.png" width="28" height="33"/></a>';
put ' </p> </div> ';
put ' <br /> ';
In the above code , instead of the WWW.GOOGLE.COM, I have URLS present in my dataset. I need to pass those URL's here based on few conditions.
Could anyone please let me know how to add conditions here and how to pass the URL from the dataset to HTML.
Thanks!!
By condition, do you mean conditions applied to a whole observation (meaning that no output will be created for this observation), or conditions to modify the output of a single observation?
How to add a variable to a put:
put ' <p><a href="' myurl +(-1) '">Google</a> ';
(the +(-1) is a trick to get rid of an unwanted blank)
Hi Kurt,
I meant the logics as conditions.
for example,
if report_name = consolidated , then <a href = &report_link. >
I will have to take the URL of this report consolidated, which is stored in the variable Report_Link and pass it in the <a href = >.
the solution you gave will work if I hardcode the URL. but I need to pass the URL from a sas dataset variable(in the above example, the variable might be something like Report_URL.
So basically how to bring the data from sas dataset to the HTML Div statement.
Hope this is clear. Please let me know if you need more details.
Thanks!!
@somu19tec wrote:
Hi Kurt,
I meant the logics as conditions.
for example,
if report_name = consolidated , then <a href = &report_link. >
I will have to take the URL of this report consolidated, which is stored in the variable Report_Link and pass it in the <a href = >.
the solution you gave will work if I hardcode the URL. but I need to pass the URL from a sas dataset variable(in the above example, the variable might be something like Report_URL.
So basically how to bring the data from sas dataset to the HTML Div statement.
Hope this is clear. Please let me know if you need more details.
Thanks!!
myurl in my code example IS a data step variable. To make the text within the anchor dynamic, use another data step variable there, in the same fashion:
put ' <p><a href="' myurl +(-1) '">' mytext +(-1) '</a></p> ';
Hi Kurt,
Thanks for the response. I got your point.
Could you please share me your code where you have your dataset called. so that I can try with the same way and check if my variable in getting passed.
Thanks!!
See this:
data test;
input myurl :$40. mytext $40.;
datalines;
www.google.com Google
;
data _null_;
set test;
file print;
put ' <p><a href="' myurl +(-1) '">' mytext +(-1) '</a></p> ';
run;
This is what you get in the results window:
<p><a href="www.google.com">Google</a></p>
@somu19tec wrote:
Hi Kurt,
Thanks for the sample code. My question next would be I have multiple rows
in my dataset , so how do I restrict to one row in the display. Or may be 2
rows in the display.
Thanks
Use a where condition
where myurl ne 'www.google.com';
or a subsetting if
if myurl ne 'www.google.com';
Hi Kurt ,
I tried the below code and also added the output .
data test;
input user myurl :$40. mytest $40.;
datalines;
23 www.google.com Google
23 www.yahoo.com Yahoo
;
data _null_;
set test;
file _webout;
put '<HTML>';
put '<HEAD>WWW Sites </HEAD>';
put '<body>';
put '<p><a href ="'myurl '">'mytest ' </a> </p>';
put '</body>';
put '</HTML>';
run;
The output I get is something like this
www sites
Google
www sites
Yahoo
The output I am looking for is like this
Www sites
Google
Yahoo
Could you please guide me how to get this output.
Thanks
You need to restrict writing the top and bottom of the HTML to only once. To do this, use the data step iteration counter (_n_) and the end= option of the set statement:
data test;
input user myurl :$40. mytest $40.;
datalines;
23 www.google.com Google
23 www.yahoo.com Yahoo
;
data _null_;
set test end=eof;
file _webout;
if _n_ = 1
then do;
put '<HTML>';
put '<HEAD>WWW Sites </HEAD>';
put '<body>';
end;
put '<p><a href ="'myurl '">'mytest ' </a> </p>';
if eof
then do;
put '</body>';
put '</HTML>';
end;
run;
No need for the +(-1) trick for this problem.
Just use the $QUOTE format.
put ' <p><a href=' myurl :$quote. '>Google</a> ';
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.