I am making an API GET call that returns a field I need in the headers. I am able to get the headers into a file using headerout. How do I pull a specific header value into a variable? Here is what I part of the output from headerout.
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 3.0
X-MWS-CV-Last-Updated: 2020-12-07T21:54:45
X-AspNet-Version: 4.0.30319I need to retrieve just X-MWS-CV-Last-Updated. Is there a way to do that short of text parsing the entire thing?
There is no built-in reader for parsing header files. You can perform simple text processing as follows to get either name/value data set, or single row table after transposing.
Example:
filename header temp; * simulate header returned from API GET call; data _null_; file header; input; put _infile_; datalines; Server: Microsoft-IIS/10.0 X-AspNetMvc-Version: 3.0 X-MWS-CV-Last-Updated: 2020-12-07T21:54:45 X-AspNet-Version: 4.0.30319 ; data header_items; length name value $200; infile header; input; _cpos = index(_infile_,':'); name = substr(_infile_,1,_cpos-1); value = substr(_infile_,_cpos+1); run; proc transpose data=header_items out=header_vars(drop=_name_); id name; var value; run;
Name Value pairs
Header attribute name as column name (after transpose)
There is no built-in reader for parsing header files. You can perform simple text processing as follows to get either name/value data set, or single row table after transposing.
Example:
filename header temp; * simulate header returned from API GET call; data _null_; file header; input; put _infile_; datalines; Server: Microsoft-IIS/10.0 X-AspNetMvc-Version: 3.0 X-MWS-CV-Last-Updated: 2020-12-07T21:54:45 X-AspNet-Version: 4.0.30319 ; data header_items; length name value $200; infile header; input; _cpos = index(_infile_,':'); name = substr(_infile_,1,_cpos-1); value = substr(_infile_,_cpos+1); run; proc transpose data=header_items out=header_vars(drop=_name_); id name; var value; run;
Name Value pairs
Header attribute name as column name (after transpose)
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.