sas

SAS: how to bring values in the next couple of rows to the current row but don't know how far down to look

♀尐吖头ヾ 提交于 2020-01-06 05:17:25
问题 I have a data set that tracks the location change for a person. The data set includes person ID, a serial number for records within person ID, start datetime for the current location, leave datetime for this location, current location code and the prior location code. My goal is to reorganize the data set so that I know on each row for a location how long the person actually stayed and the rows should still stay in the order ofdate/time ascending. see a snippet of the data set for example

How can I read in data with uneven spacings?

早过忘川 提交于 2020-01-05 09:09:03
问题 I have data which doesn't appear to have consistent spacings or positioning. It looks like: 1675 C Street , Suite 201 Anchorage AK 99501 61.205475 -149.886882 600 Azalea Road Mobile AL 36609 30.656824 -88.148781 1601 Harbor Bay Parkway , Suite 150 Alameda CA 94502 37.726114 -122.240546 1900 Point West Way, Suite 270 Sacramento CA 95815 38.5994175 -121.4315844 3600 Wilshire Blvd., Suite 1500 Los Angeles CA 90010 34.06153 -118.303463 From this I'd like to extract the street address, city name,

Loop over strings and read in files and save [duplicate]

倖福魔咒の 提交于 2020-01-05 08:47:06
问题 This question already has answers here : Append multiple CSV files in SAS (5 answers) Closed 4 years ago . I am pretty new to SAS. I have a bunch of files that are in csv format that I want to read into SAS. I need to read them in one-by-one and save them, either individually or preferably in one huge file. (Although the file might be really large...not sure how to best deal with this - MySQL maybe?) Say the file are named like this: file97.csv file98.csv file99.csv file00.csv file01.csv

Calculate Skewness in PROC REPORT

流过昼夜 提交于 2020-01-05 08:40:56
问题 I have the following sample data with I'm creating a crosstab for: data have1; input username $ betdate : datetime. stake winnings; dateOnly = datepart(betdate) ; format betdate DATETIME.; format dateOnly ddmmyy8.; datalines; player1 12NOV2008:12:04:01 90 -90 player1 04NOV2008:09:03:44 100 40 player2 07NOV2008:14:03:33 120 -120 player1 05NOV2008:09:00:00 50 15 player1 05NOV2008:09:05:00 30 5 player1 05NOV2008:09:00:05 20 10 player2 09NOV2008:10:05:10 10 -10 player2 15NOV2008:15:05:33 35 -35

Simple way to do a weighted hot deck imputation in Stata?

浪尽此生 提交于 2020-01-05 06:21:08
问题 I'd like to do a simple weighted hot deck imputation in Stata. In SAS the equivalent command would be the following (and note that this is a newer SAS feature, beginning with SAS/STAT 14.1 in 2015 or so): proc surveyimpute method=hotdeck(selection=weighted); For clarity then, the basic requirements are: Imputations most be row-based or simultaneous. If row 1 donates x to row 3, then it must also donate y . Must account for weights. A donor with weight=2 should be twice as likely to be

SAS proc sql inside %macro

▼魔方 西西 提交于 2020-01-05 04:05:31
问题 Firstly I have the following table: data dataset; input id $ value; datalines; A 1 A 2 A 3 A 4 B 2 B 3 B 4 B 5 C 2 C 4 C 6 C 8 ; run; I would like to write a macro so that the user can subset the data by giving the id value. I do proc sql inside the macro as follows: %macro sqlgrp(id=,); proc sql; create table output_&id. as select * from dataset where id = '&id.' ; quit; %mend; %sqlgrp(id=A); /*select id=A only*/ I am able to generate the output_A table in the WORK library, however it has

SAS Do loops: use loop variable inside the loop to create lagged variables

梦想与她 提交于 2020-01-04 13:48:12
问题 I would like to create variables containing lagged values of a given variable for a large number of lags. How could I do this? I try the following: data out; set in; do i = 1 to 50; %let j = i; lag_&j = Lag&j.(x); end; run; How can I get the loop variable i into the macro variable j or how to use it directly to create the appropriately named variable and for the Lag function? 回答1: Chris J answers the question, but here i'll provide my preferred way of doing this. %macro lagvar(var=,num=); %do

SAS Do loops: use loop variable inside the loop to create lagged variables

☆樱花仙子☆ 提交于 2020-01-04 13:48:10
问题 I would like to create variables containing lagged values of a given variable for a large number of lags. How could I do this? I try the following: data out; set in; do i = 1 to 50; %let j = i; lag_&j = Lag&j.(x); end; run; How can I get the loop variable i into the macro variable j or how to use it directly to create the appropriately named variable and for the Lag function? 回答1: Chris J answers the question, but here i'll provide my preferred way of doing this. %macro lagvar(var=,num=); %do

How to use proc compare to update dataset

只愿长相守 提交于 2020-01-04 06:03:45
问题 I want to use proc compare to update dataset on a daily basis. work.HAVE1 Date Key Var1 Var2 01Aug2013 K1 a 2 01Aug2013 K2 a 3 02Aug2013 K1 b 4 work.HAVE2 Date Key Var1 Var2 01Aug2013 K1 a 3 01Aug2013 K2 a 3 02Aug2013 K1 b 4 03Aug2013 K2 c 1 Date and Key are uniquely determine one record. How can I use the above two tables to construct the following work.WANT Date Key Var1 Var2 01Aug2013 K1 a 3 01Aug2013 K2 a 3 02Aug2013 K1 b 4 03Aug2013 K2 c 1 I don't want to delete the previous data and

Problems with SAS DDE with Office 2010

丶灬走出姿态 提交于 2020-01-04 02:47:11
问题 When I was running office 2007, my SAS DDE script populated, saved and closed the excel file just fine. I recently updated to office 2010 and the population works fine...but excel stops at the save dialog box. I have to manually click on Save which I did not have to do before. Anyone know how to fix this issue? Codes I am using: filename commands DDE 'EXCEL|SYSTEM'; data _null_; file commands; put '[OPEN("pathtoexcelfile.xls")]'; run; data _null_; file commands; put "[Save.as(""&saveas_Path.