sas-macro

Concatenate quoted macro variables

馋奶兔 提交于 2019-11-30 05:35:52
问题 I'm just trying to concatenate two quoted macro variables but there doesn't seem to be an easy way. Say we have: %LET VAR1="This is not the greatest song in the world"; %LET VAR2="this is just a tribute."; %LET TRIBUTE=%SYSFUNC(CATX(%STR( ),&VAR1,&VAR2)); %PUT &TRIBUTE; I actually want: "This is not the greatest song in the world this is just a tribute." But the above code actually yields: "This is not the greatest song in the world" "this is just a tribute." So I try putting %QUOTE() ,

Is it possible to loop over SAS datasets?

元气小坏坏 提交于 2019-11-29 08:26:13
问题 I have 60 sas datasets that contain data on consumers individual characteristics such as id, gender, age, amountSpent, .... Each dataset shows data only for one time period (data1 is Jan, data2 is Feb...). I cannot merge them because of the size and some other issues. How can I write a multiple loop to go through each of the datasets, do some manipulations and save the estimated values to a temporary file. SAS does not have a for loop. How can I use do ? 回答1: But sas does have a do while

Resolving multiple ampersands with macro variables

只愿长相守 提交于 2019-11-28 04:36:11
问题 This code works in SAS EG run on local (hidden sensitive information): *---- two values: DEV (ALIASDEV) and PROD (ALIASPROD); %let my_environment = ALIASDEV; %let ALIASPROD= (hidden_tns_prod); %let ALIASDEV= (hidden_tns_dev); libname mylib oracle user=username password='my_password' path="&&my_environment"; But this code doesn't (with rsubmit;) rsubmit; *---- two values: DEV (ALIASDEV) and PROD (ALIASPROD); %let my_environment = ALIASDEV; %let ALIASPROD= (hidden_tns_prod); %let ALIASDEV=

Parse JSON object in SAS macro

依然范特西╮ 提交于 2019-11-28 01:43:11
Here is the input JSON file. It have to parse in SAS dataset. "results": [ { "acct_nbr": 1234, "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" } } , { "acct_nbr": 3456, "firstName": "Sam", "lastName": "Jones", "age": 32, "address": { "streetAddress": "25 2nd Street", "city": "New Jersy", "state": "NJ", "postalCode": "10081" } } ] And I want the output for only Address field in SAS dataset like this : ACCT_NBR FIELD_NAME FIELD_VALUE 1234 streetAddress 21 2nd Street 1234 city New York

Using SAS Macro to pipe a list of filenames from a Windows directory

眉间皱痕 提交于 2019-11-27 14:30:18
I am trying to amend the macro below to accept a macro parameter as the 'location' argument for a dir command. However I cannot get it to resolve correctly due to the nested quotes issue. Using %str(%') does not work, neither do quoting functions for some reason. The macro will work fine when the filepath has no spaces (eg C:\temp\withnospace) as the middle quotes aren't needed. However I need this macro to work for filepaths with spaces (eg 'C:\temp\with space\'). Please help! %macro get_filenames(location) filename pipedir pipe "dir &location. /b " lrecl=32767; data filenames; infile pipedir

sas MACRO ampersand

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:14:35
%let test = one; %let one = two; %put &test; %put &&test; %put &&&test; %put &&&&test; %put &&&&&test; Well. I'm TOTALLY BEATEN by these ampersands. I don't understand why they need SO MANY ampersands before a macro variable. Is there any trick to master the usage of ampersand? BTW, what are the five results, correspondingly? With a single set of ampersands, what you get is pretty boring; after one, odd number of ampersands leads to resolving twice, even number of ampersands resolves once. So you use 1 ampersand to resolve once and 3 ampersands to resolve twice, unless you have stock in the

Using SAS Macro to pipe a list of filenames from a Windows directory

别来无恙 提交于 2019-11-26 16:46:12
问题 I am trying to amend the macro below to accept a macro parameter as the 'location' argument for a dir command. However I cannot get it to resolve correctly due to the nested quotes issue. Using %str(%') does not work, neither do quoting functions for some reason. The macro will work fine when the filepath has no spaces (eg C:\temp\withnospace) as the middle quotes aren't needed. However I need this macro to work for filepaths with spaces (eg 'C:\temp\with space\'). Please help! %macro get

Dynamically call macro from sas data step

醉酒当歌 提交于 2019-11-26 13:47:46
This code executes fine when Run as a SAS program: %MyMacro(foo_val, bar_val, bat_val); I have created a table using: DATA analyses; input title : $32. weight : $32. response : $32.; datalines; foo1 bar1 bat1 foo2 bar2 bat2 ; I want to execute MyMacro once for each row of the analyses table. The following code appears to only pass the string values title , weight and response (rather than the data values foo1 etc.) to my macro (tested with calls to the %put command) : DATA _NULL_ ; set analyses; %MyMacro(title, weight, response); RUN; How can I invoke the macro once per record of the analyses

sas MACRO ampersand

若如初见. 提交于 2019-11-26 10:01:58
问题 %let test = one; %let one = two; %put &test; %put &&test; %put &&&test; %put &&&&test; %put &&&&&test; Well. I\'m TOTALLY BEATEN by these ampersands. I don\'t understand why they need SO MANY ampersands before a macro variable. Is there any trick to master the usage of ampersand? BTW, what are the five results, correspondingly? 回答1: With a single set of ampersands, what you get is pretty boring; after one, odd number of ampersands leads to resolving twice, even number of ampersands resolves

Dynamically call macro from sas data step

纵然是瞬间 提交于 2019-11-26 03:44:47
问题 This code executes fine when Run as a SAS program: %MyMacro(foo_val, bar_val, bat_val); I have created a table using: DATA analyses; input title : $32. weight : $32. response : $32.; datalines; foo1 bar1 bat1 foo2 bar2 bat2 ; I want to execute MyMacro once for each row of the analyses table. The following code appears to only pass the string values title , weight and response (rather than the data values foo1 etc.) to my macro (tested with calls to the %put command) : DATA _NULL_ ; set