Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. MatthiasB

    Question about Dow-Loop SAS code

    This likely is a problem how you compare floating point numbers. Depending on how you generate your numbers on the way to the ADSK table, you could introduce some inaccuracy. Check this: 401 data _null_; 402 base = 5; 403 divide = 3333333; 404 aTear = base / divide; 405 aBucket =...
  2. MatthiasB

    Moving multiple rows to single row

    Quite some time ago, maybe still current - try something like this: proc sort data=oldTab; by tiliA tiliB; run; data newTab; set oldTab (rename=(tiliB=oneB)); by tiliA; length tiliB $50; /* or whatever length you need */ retain tiliB; if first.tiliA then tiliB = left(oneB); else...
  3. MatthiasB

    create new variable based on next row

    You can retain the >new< variable batch_id and increment it according to the specified condition, e.g. retain batch_id 0; if job_id eq 1 then batch_id = batch_id+1; Plug it into your datastep and you should have the batch_id set properly.
  4. MatthiasB

    Skip over variables when importing flat file into sas

    I tend to provide lengthy solutions, yet this makes sure you can handle these optional cases. Principle problems with you data are an optional variable placed on the data line, plus you have no delimiter between drug and manufacturer; I assume the drug is a single word, but that seems to not be...
  5. MatthiasB

    Macro to automate selection of multiple files with similar name

    Always remember that macro is used to make repetitive things easier, the repeating bits you can loop and/or parametrize for example. You have the year and the number of consecutive files as variable parts, so assuming the library and file names are fix, just add those two to the macro...
  6. MatthiasB

    HELP!!! Create Duplicate records using SAS!

    @jj72uk d(^_^)b shorter, true. Always forget about "do" w/o init and inc lines. Back to the tele again, "supernatural-on-dvd" time.
  7. MatthiasB

    HELP!!! Create Duplicate records using SAS!

    Try something like this to take firstTable and turn it into the larger secondTable (both in WORK library). The "greater-equal" comparison makes sure you do not have an endless loop on days smaller 1. data WORK.secondTable; set work.firstTable; length visit 8; visit = 1; do until (visit...
  8. MatthiasB

    Date Format

    Hi, See in PDF "SAS Language Reference: Dictionary" in "Chapter 3: Formats" the section on MMDDYYw. format for details. data _null_; length txtDate $5 numDate 8 ; /*-- as text - not so nice */ txtDate = '0225'; txtDate = substr(txtDate,1,2) !! '/' ...
  9. MatthiasB

    data step or proc sql for performance time

    Thousands of records isn't so bad, I don't think you will see much difference either way - unless sitting on >really< slow CPUs and I/O. You'd need more complex joins and lookups with 100k's or millions of records crossed with thousands to see a real difference. Then things like "SET KEY=" on...
  10. MatthiasB

    Parsing in SAS

    Hi SAP1958, should go in under 60 lines of code, get introduced to SAS/Macro: %* MACRO - read all files w/pattern FP in folder BDIR ; %* store the vautil files in table DS ; %macro rdVAUTIL (bdir=, fp=, ds=); %local numFiles; %let numFiles=0; %*-- find all files to...
  11. MatthiasB

    Parsing in SAS

    Just specify the funny 3 as a delimiter on the infile and you're set. I also suggest to specify the length of all variables on introduction - it's good practice and avoids any issue with cut-off strings or similar: data VAUTIL03; length STATE $2 NDC1 8 NDC2 8 NDC3 8...
  12. MatthiasB

    Data step sort vars by # decimal places

    You can turn the number via format to a string w/o trailing zeros and remove punctuation with compress. Below example assumes you have max width of 5 characters incl a potential dot. data x; val = 23.45; output; val = 23.4; output; val = 23.; output; run; data _null_; set x; length...
  13. MatthiasB

    selecting fields with spaces and slashes

    These should be no physical SAS columns, they look like column labels of a table view. Spaces, slashes etc are surely invalid (SAS) name characters. You have to get the column names and make the query, then it'll work.
  14. MatthiasB

    fill missing variables by cycle

    I don't get the rule for filling the f* h* columns. With knowing that and knowing how to reverse order (or using a counter _n_ variable to sort reverse), it shouldn't be hard to retain the values to fill any missing. Can you let us known the rules?
  15. MatthiasB

    converting a date in sas

    Just to make sure: the SAS format basically changes the >output< format, it does not change the content of the variable. You read in a datetime, you want date only displayed. Add line "BirthDate = datepart(BirthDate);" and you should be set. Cheers, Matthias
  16. MatthiasB

    SAS MACRO not resolving macro variables

    You are mixing the execution times of macro and the datastep in your coding. Before any datastep or other code is executed, macros are resolved and executed - regard it as a "pre-compiler". Your macro contains a datastep, and it is positioned within a datastep, so the first DS executes up to...
  17. MatthiasB

    How do I create thus new column and variable?

    Alternatively you could work with RETAIN. Assuming your input table is WORK.kids (code not tested): /* get twins into sequence, female before male */ proc sort data=WORK.kids; by idTwin sex; run; /* get groups gender */ data WORK.twinGender (keep=idTwin twinGender); set WORK.kids...
  18. MatthiasB

    Counting variables in SAS

    This works for any non-single due to only keeping "cnt gt 1" in the PROC SORT. In your case this will be all twins as the count is 2. The double entries will be single entries in the result of PROC SORT because option "nodup" is specified. So output has moms and their twins. The following...
  19. MatthiasB

    Counting variables in SAS

    Hi, I hope I understood the request correctly - the code does the following after reading in an advanced set of test data with single kids, twins and triplet: using proc sort create a table containing a unique list of mothers and their non-single kids (WORK.twinMom). From that table get the...
  20. MatthiasB

    Parse text data to extract sub-string

    Hi, this is a month ago (didn't visit this for for months), yet maybe this still helps - if I understood the problem right, here you slice nested tags: data txt; drop i; str = 'Out1<text>In1<text>In2<TeXt>Not1</TeXt></text>Post1</text>Out2'; output; do while (str ne ''); i = index...

Part and Inventory Search

Back
Top