sas-macro

When I am exporting a SAS dataset to csv; it is trimming all the leading spaces in the characters

若如初见. 提交于 2019-12-10 21:34:12
问题 When I am exporting a SAS dataset to csv; it is trimming all the leading spaces in the characters. Please help me to retain all the leading spaces in the csv output. The statement used is: Proc Export Data = Globl_Mth_Sumry OutFile = "&GMUPath.\20&RptYr._&RptMt.\03 Output\01 GMU\&Brnd_Abbr.\&Brnd._&Mkt._Globl_Mth_Sumry_&RptMt.&RptYr.&NeuronQTR..csv" DBMS = CSV Replace; Run; So, there is a column containing the list of countries which is like Asia India China etc. But the csv file is showing

SAS macro variable change

谁说胖子不能爱 提交于 2019-12-10 04:57:56
问题 In general how do we deal with the situation where macro variables need to be modified inside a macro; for example, suppose I have this macro: %macro test (arg=); array arrayone [&arg]; /* This is ok */ array arraytwo [&arg+1] /* This is not ok. How to make it work? */ ... How do we manage these situation when I want %test(3) and then the arraytwo needs to take dimension 4... ? 回答1: Change it to array arraytwo[%EVAL(&ARG + 1)] ; 回答2: Using %eval is sufficient as long as you only require

SAS Macro coding

十年热恋 提交于 2019-12-09 03:29:08
问题 I dont understand what is going on in my SAS code. The code behaves as expected, but only during the first time it compiles, i.e. the table called 'SummaryTable' shows the correct 'LogLik' value for each of the 3 iterations where the code triggers %mylogreg and %ModelsSummary. However, if I re-run the code then it behaves differently, the 'LogLik' value for the 3 iterations is the same and it is equal to the value for the last iteration. So, in some way the variable 'MyLogLik' saved the value

Open code statement recursion detected during exporting a file

怎甘沉沦 提交于 2019-12-08 09:16:12
问题 I try to export a file in SAS but I get "Open code statement recursion detected." error. Since I export more than one files depending on date I define as a macro variable based on the prompt date, I want to name my file to be exported with this variable but it does not work. I would really appreciate if anyone helps me. rep_date = 30APR2015:00:00:00 Outfile = work.A042015.sas7 %let var = CATS("A",MONTH(DATEPART(&rep_date)),YEAR(DATEPART(&rep_date))); data WORK.&var(compress=yes); set WORK

SAS macro to resolve in proc sql into statement

試著忘記壹切 提交于 2019-12-08 08:52:27
Can anyone help me with the syntax error here. Y is dataset which contain some value let's say 1,2,3,4 (Actually it contains many records) /*This is working fine*/ proc sql; select count(*) into:m from y; select x into:a1 - :a4 from y; quit; %put &m &a1 &a2 &a3 &a4; /*When i am trying to create a macro which will have a1 to a4 values, it's giving me error. below is my approach*/ proc sql; select count(*) into:m from y; select x into:a1 - :a||trim(left(&m.)) from y; quit; %put &m &a1 &a2 &a3 &a4; Please can someone help me with this, explain me the reason for error. data _null_ You don't need

How to pass macro variable to PROC SQL on IN statement in WHERE clause on MS SQL Server

爱⌒轻易说出口 提交于 2019-12-08 07:29:07
问题 I have a table in MS SQL Server that looks like: ID, Code 01, A 02, A 03, B 04, C ... and is defined in SAS as LIBNAME MSSQLDB ODBC CONNECTION=SHAREDREAD COMPLETE='Description=OIPE DW (Dev);DRIVER=SQL Server Native Client 11.0;SERVER=Amazon;Trusted_Connection=Yes;DATABASE=OIPEDW_Dev;' SCHEMA='dbo' PRESERVE_TAB_NAMES=YES PRESERVE_COL_NAMES=YES; I have a SAS dataset that has records of the same format as MSSQLDB (ID and Code variables) but is just a subset of the full database. I would like to

SAS macro to resolve in proc sql into statement

狂风中的少年 提交于 2019-12-08 06:15:18
问题 Can anyone help me with the syntax error here. Y is dataset which contain some value let's say 1,2,3,4 (Actually it contains many records) /*This is working fine*/ proc sql; select count(*) into:m from y; select x into:a1 - :a4 from y; quit; %put &m &a1 &a2 &a3 &a4; /*When i am trying to create a macro which will have a1 to a4 values, it's giving me error. below is my approach*/ proc sql; select count(*) into:m from y; select x into:a1 - :a||trim(left(&m.)) from y; quit; %put &m &a1 &a2 &a3

Random sampling without replacement in longitudinal data

落爺英雄遲暮 提交于 2019-12-07 21:03:16
问题 My data is longitudinal. VISIT ID VAR1 1 001 ... 1 002 ... 1 003 ... 1 004 ... ... 2 001 ... 2 002 ... 2 003 ... 2 004 ... Our end goal is picking out 10% each visit to run a test. I tried to use proc SURVEYSELECT to do SRS without replacement and using "VISIT" as strata. But the final sample would have duplicated IDs. For example, ID=001 might be selected both in VISIT=1 and VISIT=2. Is there any way to do that using SURVEYSELECT or other procedure (R is also fine)? Thanks a lot. 回答1: This

Parsing header line separately in SAS

倖福魔咒の 提交于 2019-12-07 15:27:02
问题 I have input file, in which the first line has header information. (Data values which are tab-separated). Amongst these values, there is an integer value that specifies how the rest of the file should be parsed. If this value is less than a threshold value, then the file should be parsed in one way, otherwise if the value is greater that the threshold value, then the data should be parsed in a different way. %let isNew = Undefined; data header; infile "&infile" OBS=1; INPUT Agency $ Status $

Finding all possible paths in a dataset using sas

混江龙づ霸主 提交于 2019-12-06 16:30:43
问题 I want to compare two columns in the dataset shown below Pid cid 1 2 2 3 2 5 3 6 4 8 8 9 9 4 Then produce a result like below 1 2 3 6 1 2 5 2 3 6 2 5 3 6 4 8 9 4 8 9 4 9 4 First we print the first two values 1 and 2, search for 2 in first column, if its present print its corresponding value from column 2, which is 3. Search for 3 in column 1, if present print the corresponding value from column 2 which is 6 How can this be done using SAS? 回答1: The links comprise a directed graph and need