Hi,
I'm looking for a way to parsing a query string and storing values during data step.
For example...
So i don't know the number of query parameters, and the set of query parameters used can be different. I'm thinking that I'll need to use an array and some macro but wondering if anyone has an easy way to do this and can give me some better ideas. Thanks! John
data data_logfile;
set someLogfile;
queryString_2=translate(queryString,'&','?');
count = countc(queryString_2,'&');
/*PARSE QUERY STING INTO AN ARRAY*/
/*WALK THROUGH THE QUERY STRING AND ASSIGN THE VALUE OF THE QUERY PARAMETER TO THE APPROPRIATE TABLE VARIABLE*/
do while i<count;
i+1;
end;
run;
I'm not quite sure what you expect but I think you might write that data out to a text file and then read it using NAMED input with a delimiter of &.
Though if your values have imbedded spaces this may not work but could be doable making sure there are two spaces before each variable name (i.e. replace the & with two spaces.
You really should provide at least a couple of lines of data for use to look at.
Thank you. Here is an example of the data that we get. We can retrieve it from the server its stored on, but we are limited right now in our ability to re-write the data into a text file. We're exploring SAS as a option for parsing it into meaningful pieces. There is other data in the file, but we are only interested in cs-uri-stem
Better off storing this as name/value pairs.
data have;
input querystring & $100. ;
cards4;
&qp_ab=value1&qp_bc=value2&qp_ac=value3...&qp_i=valuei
&qp_ab=value1&qp_ac=value3...&qp_x=valuex
;;;;
data want ;
set have;
* assign QUERYSTRING to NEXT to force SAS to define the length ;
next=querystring;
do i=1 by 1 until (next=' ');
next=scan(querystring,i,'&','Q');
name = scan(next,1,'=');
value = substr(next,length(name)+2);
if name ne ' ' then output;
end;
run;
proc print;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.